CachedScript could have a copy-free path for all-ASCII scripts.
<https://webkit.org/b/152203>
Source/JavaScriptCore:
Reviewed by Antti Koivisto.
Make SourceProvider vend a StringView instead of a String.
This relaxes the promises that providers have to make about string lifetimes.
This means that on the WebCore side, CachedScript is free to cache a String
internally, while only ever exposing it as a temporary StringView.
A few extra copies (CPU, not memory) are introduced, none of them on hot paths.
- API/JSScriptRef.cpp:
- bytecode/CodeBlock.cpp:
(JSC::CodeBlock::sourceCodeForTools):
(JSC::CodeBlock::dumpSource):
- inspector/ScriptDebugServer.cpp:
(Inspector::ScriptDebugServer::dispatchDidParseSource):
(Inspector::ScriptDebugServer::dispatchFailedToParseSource):
- interpreter/Interpreter.cpp:
(JSC::Interpreter::execute):
(functionFindTypeForExpression):
(functionHasBasicBlockExecuted):
(functionBasicBlockExecutionCount):
(JSC::Lexer<T>::setCode):
(JSC::Lexer<LChar>::setCodeStart):
(JSC::Lexer<UChar>::setCodeStart):
(JSC::Parser::getToken):
(JSC::SourceCode::toUTF8):
(JSC::SourceCode::hash):
(JSC::SourceCode::view):
(JSC::SourceCode::toString): Deleted.
(JSC::SourceCodeKey::SourceCodeKey):
(JSC::SourceCodeKey::string):
(JSC::SourceProvider::getRange):
(JSC::loadAndEvaluateModule):
(JSC::loadModule):
- runtime/ErrorInstance.cpp:
(JSC::appendSourceToError):
- runtime/FunctionPrototype.cpp:
(JSC::functionProtoFuncToString):
- tools/FunctionOverrides.cpp:
(JSC::initializeOverrideInfo):
(JSC::FunctionOverrides::initializeOverrideFor):
Source/WebCore:
Reviewed by ANtti Koivisto.
Many (if not most) of script resources on the web contain nothing but ASCII characters.
Such resources, when streamed through a text decoder, will yield the exact same byte
sequence, except in anonymous heap memory instead of delicious file-backed pages.
Care is taken to ensure that the wrapper StringImpl is updated to target newly cached
resource data if an asynchronous caching notification comes in.
- loader/cache/CachedResource.cpp:
(WebCore::CachedResource::tryReplaceEncodedData):
- loader/cache/CachedResource.h:
(WebCore::CachedResource::didReplaceSharedBufferContents):
- loader/cache/CachedScript.cpp:
(WebCore::encodingMayBeAllASCII):
(WebCore::CachedScript::script):
(WebCore::CachedScript::didReplaceSharedBufferContents):
- loader/cache/CachedScript.h:
- platform/SharedBuffer.h:
- platform/cf/SharedBufferCF.cpp:
(WebCore::SharedBuffer::tryReplaceContentsWithPlatformBuffer):