Changeset 184865 in webkit for trunk/Source/JavaScriptCore
- Timestamp:
- May 26, 2015, 11:54:01 AM (10 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r184863 r184865 1 2015-05-26 Andreas Kling <[email protected]> 2 3 String.prototype.charAt() should use StringView. 4 <https://webkit.org/b/145352> 5 6 Reviewed by Darin Adler. 7 8 Remove the jsSingleCharacterSubstring() function since it's actually completely 9 counter-productive: it could create a single-character string that would retain 10 a much larger string for the duration of its lifetime. 11 12 This made sense before StringImpl learned to put its characters at the tail end 13 of its own allocation. Now that it does, it's far better to just create a new 14 single-character StringImpl. 15 16 With that out of the way, we can make String.prototype.charAt() use StringView 17 to avoid reifying substring JSStrings (and avoid some ref churn too.) 18 19 * runtime/JSString.cpp: 20 (JSC::JSRopeString::getIndexSlowCase): 21 * runtime/JSString.h: 22 (JSC::JSString::getIndex): 23 (JSC::jsSingleCharacterSubstring): Deleted. 24 * runtime/StringPrototype.cpp: 25 (JSC::stringProtoFuncCharAt): 26 (JSC::stringProtoFuncSplit): 27 1 28 2015-05-26 Yusuke Suzuki <[email protected]> 2 29 -
trunk/Source/JavaScriptCore/runtime/JSString.cpp
r184612 r184865 375 375 ASSERT(!isRope()); 376 376 RELEASE_ASSERT(i < m_value.length()); 377 return jsSingleCharacterS ubstring(exec, m_value, i);377 return jsSingleCharacterString(exec, m_value[i]); 378 378 } 379 379 -
trunk/Source/JavaScriptCore/runtime/JSString.h
r184612 r184865 46 46 JSString* jsSingleCharacterString(VM*, UChar); 47 47 JSString* jsSingleCharacterString(ExecState*, UChar); 48 JSString* jsSingleCharacterSubstring(ExecState*, const String&, unsigned offset);49 48 JSString* jsSubstring(VM*, const String&, unsigned offset, unsigned length); 50 49 JSString* jsSubstring(ExecState*, const String&, unsigned offset, unsigned length); … … 445 444 } 446 445 447 ALWAYS_INLINE JSString* jsSingleCharacterSubstring(ExecState* exec, const String& s, unsigned offset)448 {449 VM* vm = &exec->vm();450 ASSERT(offset < static_cast<unsigned>(s.length()));451 UChar c = s.characterAt(offset);452 if (c <= maxSingleCharacterString)453 return vm->smallStrings.singleCharacterString(c);454 return JSString::create(*vm, StringImpl::createSubstringSharingImpl(s.impl(), offset, 1));455 }456 457 446 inline JSString* jsNontrivialString(VM* vm, const String& s) 458 447 { … … 508 497 return static_cast<JSRopeString*>(this)->getIndexSlowCase(exec, i); 509 498 ASSERT(i < m_value.length()); 510 return jsSingleCharacterS ubstring(exec, m_value, i);499 return jsSingleCharacterString(exec, m_value[i]); 511 500 } 512 501 -
trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp
r184346 r184865 786 786 if (!checkObjectCoercible(thisValue)) 787 787 return throwVMTypeError(exec); 788 String s = thisValue.toString(exec)->value(exec); 789 unsigned len = s.length(); 788 StringView string = thisValue.toString(exec)->view(exec); 790 789 JSValue a0 = exec->argument(0); 791 790 if (a0.isUInt32()) { 792 791 uint32_t i = a0.asUInt32(); 793 if (i < len)794 return JSValue::encode(jsSingleCharacterS ubstring(exec, s, i));792 if (i < string.length()) 793 return JSValue::encode(jsSingleCharacterString(exec, string[i])); 795 794 return JSValue::encode(jsEmptyString(exec)); 796 795 } 797 796 double dpos = a0.toInteger(exec); 798 if (dpos >= 0 && dpos < len)799 return JSValue::encode(jsSingleCharacterS ubstring(exec, s, static_cast<unsigned>(dpos)));797 if (dpos >= 0 && dpos < string.length()) 798 return JSValue::encode(jsSingleCharacterString(exec, string[static_cast<unsigned>(dpos)])); 800 799 return JSValue::encode(jsEmptyString(exec)); 801 800 } … … 1247 1246 1248 1247 do { 1249 result->putDirectIndex(exec, position, jsSingleCharacterS ubstring(exec, input, position));1248 result->putDirectIndex(exec, position, jsSingleCharacterString(exec, input[position])); 1250 1249 } while (++position < limit); 1251 1250
Note:
See TracChangeset
for help on using the changeset viewer.