@@ -101,26 +101,28 @@ bool ParserAtomEntry::equalsJSAtom(JSAtom* other) const {
101
101
: EqualChars (latin1Chars (), other->twoByteChars (nogc), length_);
102
102
}
103
103
104
- UniqueChars ParserAtomToPrintableString (JSContext* cx, const ParserAtom* atom) {
104
+ template <typename CharT>
105
+ UniqueChars ToPrintableStringImpl (JSContext* cx, mozilla::Range<CharT> str) {
105
106
Sprinter sprinter (cx);
106
107
if (!sprinter.init ()) {
107
108
return nullptr ;
108
109
}
109
- size_t length = atom->length ();
110
- if (atom->hasLatin1Chars ()) {
111
- if (!QuoteString<QuoteTarget::String>(
112
- &sprinter, mozilla::Range (atom->latin1Chars (), length))) {
113
- return nullptr ;
114
- }
115
- } else {
116
- if (!QuoteString<QuoteTarget::String>(
117
- &sprinter, mozilla::Range (atom->twoByteChars (), length))) {
118
- return nullptr ;
119
- }
110
+ if (!QuoteString<QuoteTarget::String>(&sprinter, str)) {
111
+ return nullptr ;
120
112
}
121
113
return sprinter.release ();
122
114
}
123
115
116
+ UniqueChars ParserAtomToPrintableString (JSContext* cx, const ParserAtom* atom) {
117
+ size_t length = atom->length ();
118
+
119
+ return atom->hasLatin1Chars ()
120
+ ? ToPrintableStringImpl (
121
+ cx, mozilla::Range (atom->latin1Chars (), length))
122
+ : ToPrintableStringImpl (
123
+ cx, mozilla::Range (atom->twoByteChars (), length));
124
+ }
125
+
124
126
bool ParserAtomEntry::isIndex (uint32_t * indexp) const {
125
127
size_t len = length ();
126
128
if (len == 0 || len > UINT32_CHAR_BUFFER_LENGTH) {
@@ -155,6 +157,16 @@ bool ParserAtomEntry::toNumber(JSContext* cx, double* result) const {
155
157
: CharsToNumber (cx, twoByteChars (), length (), result);
156
158
}
157
159
160
+ #if defined(DEBUG) || defined(JS_JITSPEW)
161
+ void ParserAtomEntry::dumpCharsNoQuote (js::GenericPrinter& out) const {
162
+ if (hasLatin1Chars ()) {
163
+ JSString::dumpCharsNoQuote<Latin1Char>(latin1Chars (), length (), out);
164
+ } else {
165
+ JSString::dumpCharsNoQuote<char16_t >(twoByteChars (), length (), out);
166
+ }
167
+ }
168
+ #endif
169
+
158
170
ParserAtomsTable::ParserAtomsTable (JSContext* cx)
159
171
: entrySet_(cx), wellKnownTable_(*cx->runtime ()->commonParserNames) {}
160
172
@@ -425,21 +437,37 @@ bool WellKnownParserAtoms::initSingle(JSContext* cx, const ParserName** name,
425
437
MOZ_ASSERT (FindSmallestEncoding (UTF8Chars (str, len)) ==
426
438
JS::SmallestEncoding::ASCII);
427
439
428
- UniqueLatin1Chars copy (cx->pod_malloc <Latin1Char>(len));
429
- if (!copy) {
430
- return false ;
431
- }
432
- mozilla::PodCopy (copy.get (), reinterpret_cast <const Latin1Char*>(str), len);
433
-
434
- InflatedChar16Sequence<Latin1Char> seq (copy.get (), len);
440
+ InflatedChar16Sequence<Latin1Char> seq (
441
+ reinterpret_cast <const Latin1Char*>(str), len);
435
442
SpecificParserAtomLookup<Latin1Char> lookup (seq);
443
+ HashNumber hash = lookup.hash ();
436
444
437
- auto maybeEntry =
438
- ParserAtomEntry::allocate (cx, std::move (copy), len, lookup.hash ());
439
- if (maybeEntry.isErr ()) {
440
- return false ;
445
+ UniquePtr<ParserAtomEntry> entry = nullptr ;
446
+
447
+
448
+ if (len <= ParserAtomEntry::MaxInline<Latin1Char>()) {
449
+ auto maybeEntry =
450
+ ParserAtomEntry::allocateInline<Latin1Char>(cx, seq, len, hash);
451
+ if (maybeEntry.isErr ()) {
452
+ return false ;
453
+ }
454
+ entry = maybeEntry.unwrap ();
455
+
456
+
457
+ } else {
458
+ UniqueLatin1Chars copy (cx->pod_malloc <Latin1Char>(len));
459
+ if (!copy) {
460
+ return false ;
461
+ }
462
+ mozilla::PodCopy (copy.get (), reinterpret_cast <const Latin1Char*>(str), len);
463
+ auto maybeEntry = ParserAtomEntry::allocate (cx, std::move (copy), len, hash);
464
+ if (maybeEntry.isErr ()) {
465
+ return false ;
466
+ }
467
+ entry = maybeEntry.unwrap ();
441
468
}
442
- UniquePtr<ParserAtomEntry> entry = maybeEntry.unwrap ();
469
+
470
+
443
471
const ParserName* nm = entry.get ()->asName ();
444
472
if (!entrySet_.putNew (lookup, std::move (entry))) {
445
473
return false ;
0 commit comments