| 304 | } |
| 305 | |
| 306 | Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, Error &r_error, const String &p_owner) { |
| 307 | MutexLock lock(singleton->mutex); |
| 308 | |
| 309 | if (!p_owner.is_empty()) { |
| 310 | singleton->dependencies[p_owner].insert(p_path); |
| 311 | } |
| 312 | if (singleton->full_gdscript_cache.has(p_path)) { |
| 313 | return singleton->full_gdscript_cache[p_path]; |
| 314 | } |
| 315 | if (singleton->shallow_gdscript_cache.has(p_path)) { |
| 316 | return singleton->shallow_gdscript_cache[p_path]; |
| 317 | } |
| 318 | |
| 319 | const String remapped_path = ResourceLoader::path_remap(p_path); |
| 320 | |
| 321 | Ref<GDScript> script; |
| 322 | script.instantiate(); |
| 323 | script->set_path(p_path, true); |
| 324 | if (remapped_path.get_extension().to_lower() == "gdc") { |
| 325 | Vector<uint8_t> buffer = get_binary_tokens(remapped_path); |
| 326 | if (buffer.is_empty()) { |
| 327 | r_error = ERR_FILE_CANT_READ; |
| 328 | } |
| 329 | script->set_binary_tokens_source(buffer); |
| 330 | } else { |
| 331 | r_error = script->load_source_code(remapped_path); |
| 332 | } |
| 333 | |
| 334 | if (r_error) { |
| 335 | return Ref<GDScript>(); // Returns null and does not cache when the script fails to load. |
| 336 | } |
| 337 | |
| 338 | Ref<GDScriptParserRef> parser_ref = get_parser(p_path, GDScriptParserRef::PARSED, r_error); |
| 339 | if (r_error == OK) { |
| 340 | GDScriptCompiler::make_scripts(script.ptr(), parser_ref->get_parser()->get_tree(), true); |
| 341 | } |
| 342 | |
| 343 | singleton->shallow_gdscript_cache[p_path] = script; |
| 344 | |
| 345 | return script; |
| 346 | } |
| 347 | |
| 348 | Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_error, const String &p_owner, bool p_update_from_disk) { |
| 349 | MutexLock lock(singleton->mutex); |
nothing calls this directly
no test coverage detected