Lines 39-54
Link Here
|
39 |
* ***** END LICENSE BLOCK ***** */ |
39 |
* ***** END LICENSE BLOCK ***** */ |
40 |
|
40 |
|
41 |
#include "mozilla/RangedPtr.h" |
41 |
#include "mozilla/RangedPtr.h" |
42 |
|
42 |
|
43 |
#include "jsgcmark.h" |
43 |
#include "jsgcmark.h" |
44 |
|
44 |
|
45 |
#include "String.h" |
45 |
#include "String.h" |
46 |
#include "String-inl.h" |
46 |
#include "String-inl.h" |
|
|
47 |
#include "jsgcchunk.h" |
47 |
|
48 |
|
48 |
using namespace mozilla; |
49 |
using namespace mozilla; |
49 |
using namespace js; |
50 |
using namespace js; |
50 |
|
51 |
|
51 |
bool |
52 |
bool |
52 |
JSString::isShort() const |
53 |
JSString::isShort() const |
53 |
{ |
54 |
{ |
54 |
bool is_short = (getAllocKind() == gc::FINALIZE_SHORT_STRING); |
55 |
bool is_short = (getAllocKind() == gc::FINALIZE_SHORT_STRING); |
Lines 393-449
JSFlatString::isIndex(uint32 *indexp) co
Link Here
|
393 |
* the lowercase letters, and the next 26 are the uppercase letters. |
394 |
* the lowercase letters, and the next 26 are the uppercase letters. |
394 |
*/ |
395 |
*/ |
395 |
#define TO_SMALL_CHAR(c) ((c) >= '0' && (c) <= '9' ? (c) - '0' : \ |
396 |
#define TO_SMALL_CHAR(c) ((c) >= '0' && (c) <= '9' ? (c) - '0' : \ |
396 |
(c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 10 : \ |
397 |
(c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 10 : \ |
397 |
(c) >= 'A' && (c) <= 'Z' ? (c) - 'A' + 36 : \ |
398 |
(c) >= 'A' && (c) <= 'Z' ? (c) - 'A' + 36 : \ |
398 |
StaticStrings::INVALID_SMALL_CHAR) |
399 |
StaticStrings::INVALID_SMALL_CHAR) |
399 |
|
400 |
|
400 |
#define R TO_SMALL_CHAR |
401 |
#define R TO_SMALL_CHAR |
|
|
402 |
#ifdef JS_MMEM_FOR_STATIC_STRINGS |
403 |
const StaticStrings::SmallChar StaticStrings::toSmallCharConstImage[] = { R7(0) }; |
404 |
#else /* JS_MMEM_FOR_STATIC_STRINGS */ |
401 |
const StaticStrings::SmallChar StaticStrings::toSmallChar[] = { R7(0) }; |
405 |
const StaticStrings::SmallChar StaticStrings::toSmallChar[] = { R7(0) }; |
|
|
406 |
#endif /* JS_MMEM_FOR_STATIC_STRINGS */ |
402 |
#undef R |
407 |
#undef R |
403 |
|
408 |
|
|
|
409 |
StaticStrings::~StaticStrings() |
410 |
{ |
411 |
#ifdef JS_MMEM_FOR_STATIC_STRINGS |
412 |
if (initialized) { |
413 |
gc::UnmapMemory(mappedMem, sizeof(*mappedMem)); |
414 |
} |
415 |
#endif /* JS_MMEM_FOR_STATIC_STRINGS */ |
416 |
} |
417 |
|
404 |
bool |
418 |
bool |
405 |
StaticStrings::init(JSContext *cx) |
419 |
StaticStrings::init(JSContext *cx) |
406 |
{ |
420 |
{ |
407 |
SwitchToCompartment sc(cx, cx->runtime->atomsCompartment); |
421 |
if (!initialized) { |
408 |
|
422 |
|
409 |
for (uint32 i = 0; i < UNIT_STATIC_LIMIT; i++) { |
423 |
#ifdef JS_MMEM_FOR_STATIC_STRINGS |
410 |
jschar buffer[] = { i, 0x00 }; |
|
|
411 |
JSFixedString *s = js_NewStringCopyN(cx, buffer, 1); |
412 |
if (!s) |
413 |
return false; |
414 |
unitStaticTable[i] = s->morphAtomizedStringIntoAtom(); |
415 |
} |
416 |
|
424 |
|
417 |
for (uint32 i = 0; i < NUM_SMALL_CHARS * NUM_SMALL_CHARS; i++) { |
425 |
mappedMem = reinterpret_cast<MappedTables*>(gc::MapMemory(sizeof(*mappedMem))); |
418 |
jschar buffer[] = { FROM_SMALL_CHAR(i >> 6), FROM_SMALL_CHAR(i & 0x3F), 0x00 }; |
426 |
if (!mappedMem) |
419 |
JSFixedString *s = js_NewStringCopyN(cx, buffer, 2); |
|
|
420 |
if (!s) |
421 |
return false; |
427 |
return false; |
422 |
length2StaticTable[i] = s->morphAtomizedStringIntoAtom(); |
428 |
|
423 |
} |
429 |
length2StaticTable = mappedMem->length2StaticTable; |
|
|
430 |
intStaticTable = mappedMem->intStaticTable; |
431 |
unitStaticTable = mappedMem->unitStaticTable; |
432 |
toSmallChar = mappedMem->toSmallChar; |
433 |
|
434 |
for (uint32 i = 0; |
435 |
i < sizeof(toSmallCharConstImage)/sizeof(toSmallCharConstImage[0]); |
436 |
i++) |
437 |
mappedMem->toSmallChar[i] = toSmallCharConstImage[i]; |
438 |
|
439 |
#endif /* JS_MMEM_FOR_STATIC_STRINGS */ |
440 |
|
441 |
SwitchToCompartment sc(cx, cx->runtime->atomsCompartment); |
442 |
|
443 |
for (uint32 i = 0; i < UNIT_STATIC_LIMIT; i++) { |
444 |
jschar buffer[] = { i, 0x00 }; |
445 |
JSFixedString *s = js_NewStringCopyN(cx, buffer, 1); |
446 |
if (!s) { |
447 |
#ifdef JS_MMEM_FOR_STATIC_STRINGS |
448 |
gc::UnmapMemory(mappedMem, sizeof(*mappedMem)); |
449 |
#endif /* JS_MMEM_FOR_STATIC_STRINGS */ |
450 |
return false; |
451 |
} |
452 |
unitStaticTable[i] = s->morphAtomizedStringIntoAtom(); |
453 |
} |
424 |
|
454 |
|
425 |
for (uint32 i = 0; i < INT_STATIC_LIMIT; i++) { |
455 |
for (uint32 i = 0; i < NUM_SMALL_CHARS * NUM_SMALL_CHARS; i++) { |
426 |
if (i < 10) { |
456 |
jschar buffer[] = { FROM_SMALL_CHAR(i >> 6), FROM_SMALL_CHAR(i & 0x3F), 0x00 }; |
427 |
intStaticTable[i] = unitStaticTable[i + '0']; |
457 |
JSFixedString *s = js_NewStringCopyN(cx, buffer, 2); |
428 |
} else if (i < 100) { |
458 |
if (!s) { |
429 |
size_t index = ((size_t)TO_SMALL_CHAR((i / 10) + '0') << 6) + |
459 |
#ifdef JS_MMEM_FOR_STATIC_STRINGS |
430 |
TO_SMALL_CHAR((i % 10) + '0'); |
460 |
gc::UnmapMemory(mappedMem, sizeof(*mappedMem)); |
431 |
intStaticTable[i] = length2StaticTable[index]; |
461 |
#endif /* JS_MMEM_FOR_STATIC_STRINGS */ |
432 |
} else { |
|
|
433 |
jschar buffer[] = { (i / 100) + '0', ((i / 10) % 10) + '0', (i % 10) + '0', 0x00 }; |
434 |
JSFixedString *s = js_NewStringCopyN(cx, buffer, 3); |
435 |
if (!s) |
436 |
return false; |
462 |
return false; |
437 |
intStaticTable[i] = s->morphAtomizedStringIntoAtom(); |
463 |
} |
|
|
464 |
length2StaticTable[i] = s->morphAtomizedStringIntoAtom(); |
438 |
} |
465 |
} |
|
|
466 |
|
467 |
for (uint32 i = 0; i < INT_STATIC_LIMIT; i++) { |
468 |
if (i < 10) { |
469 |
intStaticTable[i] = unitStaticTable[i + '0']; |
470 |
} else if (i < 100) { |
471 |
size_t index = ((size_t)TO_SMALL_CHAR((i / 10) + '0') << 6) + |
472 |
TO_SMALL_CHAR((i % 10) + '0'); |
473 |
intStaticTable[i] = length2StaticTable[index]; |
474 |
} else { |
475 |
jschar buffer[] = { (i / 100) + '0', ((i / 10) % 10) + '0', (i % 10) + '0', 0x00 }; |
476 |
JSFixedString *s = js_NewStringCopyN(cx, buffer, 3); |
477 |
if (!s) { |
478 |
#ifdef JS_MMEM_FOR_STATIC_STRINGS |
479 |
gc::UnmapMemory(mappedMem, sizeof(*mappedMem)); |
480 |
#endif /* JS_MMEM_FOR_STATIC_STRINGS */ |
481 |
return false; |
482 |
} |
483 |
intStaticTable[i] = s->morphAtomizedStringIntoAtom(); |
484 |
} |
485 |
} |
486 |
|
487 |
initialized = true; |
439 |
} |
488 |
} |
440 |
|
489 |
|
441 |
initialized = true; |
|
|
442 |
return true; |
490 |
return true; |
443 |
} |
491 |
} |
444 |
|
492 |
|
445 |
void |
493 |
void |
446 |
StaticStrings::trace(JSTracer *trc) |
494 |
StaticStrings::trace(JSTracer *trc) |
447 |
{ |
495 |
{ |
448 |
if (!initialized) |
496 |
if (!initialized) |
449 |
return; |
497 |
return; |