Ignore:
Timestamp:
Dec 15, 2016, 8:52:20 PM (8 years ago)
Author:
Darin Adler
Message:

Use asString instead of toWTFString, toString, or getString when we already checked isString
https://bugs.webkit.org/show_bug.cgi?id=165895

Reviewed by Yusuke Suzuki.

Source/JavaScriptCore:

Once we have called isString, we should always use asString and value rather than using
functions that have to deal with non-JSString objects. This leads to slightly fewer branches,
slightly less reference count churn, since the string is stored right inside the JSString,
and obviates the need for exception handling.

  • bindings/ScriptValue.cpp:

(Inspector::jsToInspectorValue): Use asString/value instead of getString.

  • dfg/DFGOperations.cpp:

(JSC::DFG::operationMapHash): Call jsMapHash with its new arguments.

  • inspector/JSInjectedScriptHost.cpp:

(Inspector::JSInjectedScriptHost::evaluateWithScopeExtension): Use asString/value instead
of toWTFString.

  • inspector/JSJavaScriptCallFrame.cpp:

(Inspector::JSJavaScriptCallFrame::evaluateWithScopeExtension): Ditto.

  • inspector/agents/InspectorHeapAgent.cpp:

(Inspector::InspectorHeapAgent::getPreview): Use asString/tryGetValue, instead of the
peculiar getString(nullptr) that was here before.

  • jsc.cpp:

(functionGetGetterSetter): Use asString/toIdentifier instead of the much less efficient
toWTFString/Identifier::fromString.
(functionIsRope): Use asString instead of jsCast<JSString*>; same thing, but we should
prefer the asString function, since it exists.
(functionFindTypeForExpression): Use asString/value instead of getString.
(functionHasBasicBlockExecuted): Ditto.
(functionBasicBlockExecutionCount): Ditto.
(functionCreateBuiltin): Use asString/value instead of toWTFString and removed
unneeded RETURN_IF_EXCEPTION.
(valueWithTypeOfWasmValue): Use asString instead of jsCast<String*>.
(box): Ditto.

  • runtime/DateConstructor.cpp:

(JSC::constructDate): Use asString/values instead of getString.

  • runtime/ExceptionHelpers.cpp:

(JSC::errorDescriptionForValue): Tweaked formatting.

  • runtime/HashMapImpl.h:

(JSC::jsMapHash): Changed this function to use asString/value.

  • runtime/JSCJSValue.cpp:

(JSC::JSValue::dumpInContextAssumingStructure): Use asString instead of
jsCast<JSString*>.
(JSC::JSValue::dumpForBacktrace): Ditto.

  • runtime/JSCJSValueInlines.h:

(JSC::toPreferredPrimitiveType): Ditto.

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncEval): Use asString/value instead of toWTFString.

  • runtime/JSString.cpp:

(JSC::JSString::destroy): Streamlined by removing local variable.
(JSC::JSString::estimatedSize): Use asString instead of jsCast<JSString*>.
(JSC::JSString::visitChildren): Ditto.
(JSC::JSString::toThis): Ditto.

  • runtime/JSString.h:

(JSC::JSValue::toString): Ditto.
(JSC::JSValue::toStringOrNull): Ditto.

  • runtime/NumberPrototype.cpp:

(JSC::numberProtoFuncValueOf): Ditto.

  • runtime/ObjectPrototype.cpp:

(JSC::objectProtoFuncToString): Ditto.

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncRepeatCharacter): Ditto.
(JSC::stringProtoFuncSubstr): Ditto.
(JSC::builtinStringSubstrInternal): Simplified assertion by removing local variable.

Source/WebCore:

  • Modules/fetch/FetchBody.cpp:

(WebCore::FetchBody::extract): Use asString/value instead of toWTFString.

  • Modules/mediastream/SDPProcessor.cpp:

(WebCore::SDPProcessor::callScript): Use asString/value instead of getString.

  • bindings/js/ArrayValue.cpp:

(WebCore::ArrayValue::get): Use asString/value instead of toWTFString.

  • bindings/js/IDBBindingUtilities.cpp:

(WebCore::get): Use asString/length instead of toString/length.
(WebCore::createIDBKeyFromValue): Use asString/value instead of toWTFString.

  • bindings/js/JSCryptoAlgorithmDictionary.cpp:

(WebCore::JSCryptoAlgorithmDictionary::getAlgorithmIdentifier): Ditto.

  • bindings/js/JSDataCueCustom.cpp:

(WebCore::constructJSDataCue): Use asString/value instead of getString.

  • bindings/js/JSInspectorFrontendHostCustom.cpp:

(WebCore::populateContextMenuItems): Use asString/value instead of toWTFString.

  • bindings/js/ScriptController.cpp:

(WebCore::jsValueToModuleKey): Use asString/toIdentifier instead of
jsCast<JSString*>/value/Identifier::fromString.

  • bindings/js/SerializedScriptValue.cpp:

(WebCore::CloneSerializer::dumpIfTerminal): Streamline by getting rid of local variable.

  • contentextensions/ContentExtensionParser.cpp:

(WebCore::ContentExtensions::getDomainList): Use asString instead of jsCast<JSString*>.
(WebCore::ContentExtensions::loadTrigger): Use asString/value instead of toWTFString.
(WebCore::ContentExtensions::loadAction): Ditto.

  • css/FontFace.cpp:

(WebCore::FontFace::create): Use asString/value instead of getString.

Source/WebKit/mac:

  • Plugins/Hosted/NetscapePluginInstanceProxy.mm:

(WebKit::NetscapePluginInstanceProxy::addValueToArray): Use asString/value instead of
toWTFString.

  • WebView/WebView.mm:

(aeDescFromJSValue): Use asString/value instead of getString.

Source/WebKit2:

  • WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:

(WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant): Use asString/value instead of toWTFString.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jsc.cpp

    r209897 r209906  
    18771877        return JSValue::encode(jsUndefined());
    18781878
    1879     Identifier ident = Identifier::fromString(&exec->vm(), property.toWTFString(exec));
    1880 
    18811879    PropertySlot slot(value, PropertySlot::InternalMethodType::VMInquiry);
    1882     value.getPropertySlot(exec, ident, slot);
     1880    value.getPropertySlot(exec, asString(property)->toIdentifier(exec), slot);
    18831881
    18841882    JSValue result;
     
    21052103    if (!argument.isString())
    21062104        return JSValue::encode(jsBoolean(false));
    2107     const StringImpl* impl = jsCast<JSString*>(argument)->tryGetValueImpl();
     2105    const StringImpl* impl = asString(argument)->tryGetValueImpl();
    21082106    return JSValue::encode(jsBoolean(!impl));
    21092107}
     
    22832281
    22842282    RELEASE_ASSERT(exec->argument(1).isString());
    2285     String substring = exec->argument(1).getString(exec);
     2283    String substring = asString(exec->argument(1))->value(exec);
    22862284    String sourceCodeText = executable->source().view().toString();
    22872285    unsigned offset = static_cast<unsigned>(sourceCodeText.find(substring) + executable->source().startOffset());
     
    23212319
    23222320    RELEASE_ASSERT(exec->argument(1).isString());
    2323     String substring = exec->argument(1).getString(exec);
     2321    String substring = asString(exec->argument(1))->value(exec);
    23242322    String sourceCodeText = executable->source().view().toString();
    23252323    RELEASE_ASSERT(sourceCodeText.contains(substring));
     
    23392337
    23402338    RELEASE_ASSERT(exec->argument(1).isString());
    2341     String substring = exec->argument(1).getString(exec);
     2339    String substring = asString(exec->argument(1))->value(exec);
    23422340    String sourceCodeText = executable->source().view().toString();
    23432341    RELEASE_ASSERT(sourceCodeText.contains(substring));
     
    24042402        return JSValue::encode(jsUndefined());
    24052403
    2406     String functionText = exec->argument(0).toWTFString(exec);
     2404    String functionText = asString(exec->argument(0))->value(exec);
    24072405    RETURN_IF_EXCEPTION(scope, encodedJSValue());
    24082406
     
    25112509static CString valueWithTypeOfWasmValue(ExecState* exec, VM& vm, JSValue value, JSValue wasmValue)
    25122510{
    2513     JSString* type = jsCast<JSString*>(wasmValue.get(exec, makeIdentifier(vm, "type")));
     2511    JSString* type = asString(wasmValue.get(exec, makeIdentifier(vm, "type")));
    25142512
    25152513    const String& typeString = type->value(exec);
     
    25242522{
    25252523
    2526     JSString* type = jsCast<JSString*>(wasmValue.get(exec, makeIdentifier(vm, "type")));
     2524    JSString* type = asString(wasmValue.get(exec, makeIdentifier(vm, "type")));
    25272525    JSValue value = wasmValue.get(exec, makeIdentifier(vm, "value"));
    25282526
     
    25312529            return false;
    25322530
    2533         const char* str = toCString(jsCast<JSString*>(value)->value(exec)).data();
     2531        const char* str = toCString(asString(value)->value(exec)).data();
    25342532        int scanResult;
    25352533        int length = std::strlen(str);
Note: See TracChangeset for help on using the changeset viewer.