Changeset 113396 in webkit
- Timestamp:
- Apr 5, 2012 5:12:25 PM (12 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r113391 r113396 1 2012-04-05 Benjamin Poulain <bpoulain@apple.com> 2 3 Speed up the conversion from JSValue to String for bulk operations 4 https://bugs.webkit.org/show_bug.cgi?id=83243 5 6 Reviewed by Geoffrey Garen. 7 8 When making operations on primitive types, we loose some time converting 9 values to JSString in order to extract the string. 10 11 This patch speeds up some basic Array operations by avoiding the creation 12 of intermediary JSString when possible. 13 14 For the cases where we need to convert a lot of JSValue in a tight loop, 15 an inline conversion is used. 16 17 * runtime/ArrayPrototype.cpp: 18 (JSC::arrayProtoFuncToString): 19 (JSC::arrayProtoFuncToLocaleString): 20 (JSC::arrayProtoFuncJoin): 21 (JSC::arrayProtoFuncPush): 22 (JSC::arrayProtoFuncSort): 23 * runtime/CommonIdentifiers.h: 24 * runtime/JSArray.cpp: 25 (JSC::JSArray::sort): 26 * runtime/JSString.h: 27 (JSC::JSValue::toUString): 28 (JSC): 29 (JSC::inlineJSValueNotStringtoUString): 30 (JSC::JSValue::toUStringInline): 31 * runtime/JSValue.cpp: 32 (JSC::JSValue::toUStringSlowCase): 33 (JSC): 34 * runtime/JSValue.h: 35 (JSValue): 36 1 37 2012-04-05 Benjamin Poulain <bpoulain@apple.com> 2 38 -
trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp
r113355 r113396 282 282 continue; 283 283 284 UString str = element.to String(exec)->value(exec);284 UString str = element.toUString(exec); 285 285 strBuffer[k] = str.impl(); 286 286 totalSize += str.length(); … … 359 359 CallType callType = getCallData(conversionFunction, callData); 360 360 if (callType != CallTypeNone) 361 str = call(exec, conversionFunction, callType, callData, element, exec->emptyList()).to String(exec)->value(exec);361 str = call(exec, conversionFunction, callType, callData, element, exec->emptyList()).toUString(exec); 362 362 else 363 str = element.to String(exec)->value(exec);363 str = element.toUString(exec); 364 364 if (exec->hadException()) 365 365 return JSValue::encode(jsUndefined()); … … 384 384 UString separator; 385 385 if (!exec->argument(0).isUndefined()) 386 separator = exec->argument(0).to String(exec)->value(exec);386 separator = exec->argument(0).toUString(exec); 387 387 if (separator.isNull()) 388 388 separator = UString(","); … … 400 400 JSValue element = array->getIndex(k); 401 401 if (!element.isUndefinedOrNull()) 402 stringJoiner.append(element.to String(exec)->value(exec));402 stringJoiner.append(element.toUStringInline(exec)); 403 403 else 404 404 stringJoiner.append(UString()); … … 409 409 JSValue element = thisObj->get(exec, k); 410 410 if (!element.isUndefinedOrNull()) 411 stringJoiner.append(element.to String(exec)->value(exec));411 stringJoiner.append(element.toUStringInline(exec)); 412 412 else 413 413 stringJoiner.append(UString()); … … 502 502 else { 503 503 PutPropertySlot slot; 504 Identifier propertyName(exec, JSValue(static_cast<int64_t>(length) + static_cast<int64_t>(n)).to String(exec)->value(exec));504 Identifier propertyName(exec, JSValue(static_cast<int64_t>(length) + static_cast<int64_t>(n)).toUString(exec)); 505 505 thisObj->methodTable()->put(thisObj, exec, propertyName, exec->argument(n), slot); 506 506 } … … 643 643 compareResult = call(exec, function, callType, callData, jsUndefined(), l).toNumber(exec); 644 644 } else 645 compareResult = (jObj.to String(exec)->value(exec) < minObj.toString(exec)->value(exec)) ? -1 : 1;645 compareResult = (jObj.toUStringInline(exec) < minObj.toUStringInline(exec)) ? -1 : 1; 646 646 647 647 if (compareResult < 0) { -
trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h
r111433 r113396 77 77 #define JSC_COMMON_IDENTIFIERS_EACH_KEYWORD(macro) \ 78 78 macro(null) \ 79 macro(undefined) \ 79 80 macro(true) \ 80 81 macro(false) \ -
trunk/Source/JavaScriptCore/runtime/JSArray.cpp
r113391 r113396 1488 1488 1489 1489 for (size_t i = 0; i < lengthNotIncludingUndefined; i++) 1490 values[i].second = values[i].first.to String(exec)->value(exec);1490 values[i].second = values[i].first.toUStringInline(exec); 1491 1491 1492 1492 if (exec->hadException()) { -
trunk/Source/JavaScriptCore/runtime/JSString.h
r113363 r113396 463 463 } 464 464 465 inline UString JSValue::toUString(ExecState* exec) const 466 { 467 if (isString()) 468 return static_cast<JSString*>(asCell())->value(exec); 469 return toUStringSlowCase(exec); 470 } 471 472 ALWAYS_INLINE UString inlineJSValueNotStringtoUString(const JSValue& value, ExecState* exec) 473 { 474 JSGlobalData& globalData = exec->globalData(); 475 if (value.isInt32()) 476 return globalData.numericStrings.add(value.asInt32()); 477 if (value.isDouble()) 478 return globalData.numericStrings.add(value.asDouble()); 479 if (value.isTrue()) 480 return globalData.propertyNames->trueKeyword.ustring(); 481 if (value.isFalse()) 482 return globalData.propertyNames->falseKeyword.ustring(); 483 if (value.isNull()) 484 return globalData.propertyNames->nullKeyword.ustring(); 485 if (value.isUndefined()) 486 return globalData.propertyNames->undefinedKeyword.ustring(); 487 return value.toString(exec)->value(exec); 488 } 489 490 ALWAYS_INLINE UString JSValue::toUStringInline(ExecState* exec) const 491 { 492 if (isString()) 493 return static_cast<JSString*>(asCell())->value(exec); 494 495 return inlineJSValueNotStringtoUString(*this, exec); 496 } 497 465 498 } // namespace JSC 466 499 -
trunk/Source/JavaScriptCore/runtime/JSValue.cpp
r111433 r113396 284 284 } 285 285 286 UString JSValue::toUStringSlowCase(ExecState* exec) const 287 { 288 return inlineJSValueNotStringtoUString(*this, exec); 289 } 290 286 291 } // namespace JSC -
trunk/Source/JavaScriptCore/runtime/JSValue.h
r111739 r113396 204 204 double toNumber(ExecState*) const; 205 205 JSString* toString(ExecState*) const; 206 UString toUString(ExecState*) const; 207 UString toUStringInline(ExecState*) const; 206 208 JSObject* toObject(ExecState*) const; 207 209 JSObject* toObject(ExecState*, JSGlobalObject*) const; … … 252 254 JS_EXPORT_PRIVATE double toNumberSlowCase(ExecState*) const; 253 255 JS_EXPORT_PRIVATE JSString* toStringSlowCase(ExecState*) const; 256 JS_EXPORT_PRIVATE UString toUStringSlowCase(ExecState*) const; 254 257 JS_EXPORT_PRIVATE JSObject* toObjectSlowCase(ExecState*, JSGlobalObject*) const; 255 258 JS_EXPORT_PRIVATE JSObject* toThisObjectSlowCase(ExecState*) const;
Note: See TracChangeset
for help on using the changeset viewer.