MCPcopy Create free account
hub / github.com/NativeScript/android / TryLoadScriptCache

Method TryLoadScriptCache

test-app/runtime/src/main/cpp/ModuleInternal.cpp:635–663  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

633}
634
635ScriptCompiler::CachedData* ModuleInternal::TryLoadScriptCache(const std::string& path) {
636 TNSPERF();
637 if (!Constants::V8_CACHE_COMPILED_CODE) {
638 return nullptr;
639 }
640
641 auto cachePath = path + ".cache";
642
643 struct stat result;
644 if (stat(cachePath.c_str(), &result) == 0) {
645 auto cacheLastModifiedTime = result.st_mtime;
646 if (stat(path.c_str(), &result) == 0) {
647 auto jsLastModifiedTime = result.st_mtime;
648 if (jsLastModifiedTime != cacheLastModifiedTime) {
649 // files have different dates, ignore the cache file (this is enforced by the
650 // SaveScriptCache function)
651 return nullptr;
652 }
653 }
654 }
655
656 int length = 0;
657 auto data = File::ReadBinary(cachePath, length);
658 if (!data) {
659 return nullptr;
660 }
661
662 return new ScriptCompiler::CachedData(reinterpret_cast<uint8_t*>(data), length, ScriptCompiler::CachedData::BufferOwned);
663}
664
665void ModuleInternal::SaveScriptCache(const Local<Script> script, const std::string& path) {
666 if (!Constants::V8_CACHE_COMPILED_CODE) {

Callers

nothing calls this directly

Calls 1

statClass · 0.70

Tested by

no test coverage detected