diff --git a/core/src/js/DuktapeContext.h b/core/src/js/DuktapeContext.h index c31a70210a..bf18faf192 100644 --- a/core/src/js/DuktapeContext.h +++ b/core/src/js/DuktapeContext.h @@ -31,7 +31,8 @@ #define DBG(...) #define DUMPCTX(...) #endif -#define DBGCACHE(...) //LOG(__VA_ARGS__) +#define DBGCACHE(...) +//#define DBGCACHE(...) LOG(__VA_ARGS__) namespace Tangram { @@ -608,7 +609,7 @@ struct Context { //std::array lengths{}; std::array refs{}; - size_t usage = 0; + int usage = 0; void free(Context& context, const void* ptr) { const char* str = (const char*)(ptr); @@ -628,7 +629,10 @@ struct Context { const char* add(Context& context, void* ptr, size_t length) { const char* str = (const char*)ptr; int slot = -1; - for (size_t i = 0; i < usage; i++) { + for (int i = 0; i < usage; i++) { + DBGCACHE("[%d/%d]", i, usage); + assert(int64_t(ENTRIES) - int64_t(i) > 0); + if (length <= strings[i][0] && std::memcmp(&strings[i][1], str, length) == 0) { refs[i]++; DBGCACHE("[%d] found '%.*s'", refs[i], length, &strings[i][stroffset]); @@ -639,9 +643,8 @@ struct Context { } } if (slot == -1) { - if (usage < strings.size()) { - slot = usage; - usage++; + if (usage < ENTRIES) { + slot = usage++; } else { LOG("cache full: %.*s len:%d - usage:%d, slot:%d", length, str, length, usage, slot); return nullptr; @@ -655,7 +658,7 @@ struct Context { context._allocCnt++; - DBGCACHE("[%d] added: '%.*s'", refs[slot], length, out); + DBGCACHE("[%d] added: '%.*s'", refs[slot], length, str); return &strings[slot][stroffset]; }