|
28 | 28 | #include "URLImpl.h"
|
29 | 29 | #include "URLPatternImpl.h"
|
30 | 30 | #include "URLSearchParamsImpl.h"
|
| 31 | +#include <mutex> |
31 | 32 |
|
32 | 33 | #define STRINGIZE(x) #x
|
33 | 34 | #define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
@@ -116,6 +117,8 @@ static void InitializeImportMetaObject(Local<Context> context, Local<Module> mod
|
116 | 117 | std::atomic<int> Runtime::nextIsolateId{0};
|
117 | 118 | SimpleAllocator allocator_;
|
118 | 119 | NSDictionary* AppPackageJson = nil;
|
| 120 | +static std::unordered_map<std::string, id> AppConfigCache; // generic cache for app config values |
| 121 | +static std::mutex AppConfigCacheMutex; |
119 | 122 |
|
120 | 123 | // Global flag to track when JavaScript errors occur during execution
|
121 | 124 | bool jsErrorOccurred = false;
|
@@ -442,7 +445,27 @@ void DisposeIsolateWhenPossible(Isolate* isolate) {
|
442 | 445 | }
|
443 | 446 | }
|
444 | 447 |
|
445 |
| - id result = AppPackageJson[[NSString stringWithUTF8String:key.c_str()]]; |
| 448 | + // Generic cache for all keys to avoid repeated NSString conversion and NSDictionary hashing |
| 449 | + { |
| 450 | + std::lock_guard<std::mutex> lock(AppConfigCacheMutex); |
| 451 | + auto it = AppConfigCache.find(key); |
| 452 | + if (it != AppConfigCache.end()) { |
| 453 | + return it->second; |
| 454 | + } |
| 455 | + } |
| 456 | + |
| 457 | + id result = nil; |
| 458 | + if (AppPackageJson != nil) { |
| 459 | + NSString* nsKey = [NSString stringWithUTF8String:key.c_str()]; |
| 460 | + result = AppPackageJson[nsKey]; |
| 461 | + } |
| 462 | + |
| 463 | + // Store in cache (can cache nil as NSNull to differentiate presence if desired; for now, cache as-is) |
| 464 | + { |
| 465 | + std::lock_guard<std::mutex> lock(AppConfigCacheMutex); |
| 466 | + AppConfigCache[key] = result; |
| 467 | + } |
| 468 | + |
446 | 469 | return result;
|
447 | 470 | }
|
448 | 471 |
|
|
0 commit comments