Skip to content

Commit

Permalink
how can 'i' get greater than 'usage'?
Browse files Browse the repository at this point in the history
  • Loading branch information
hjanetzek committed Dec 4, 2018
1 parent 070c545 commit 8c1127b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions core/src/js/DuktapeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
#define DBG(...)
#define DUMPCTX(...)
#endif
#define DBGCACHE(...) //LOG(__VA_ARGS__)
#define DBGCACHE(...)
//#define DBGCACHE(...) LOG(__VA_ARGS__)

namespace Tangram {

Expand Down Expand Up @@ -608,7 +609,7 @@ struct Context {
//std::array<uint8_t, SIZE> lengths{};
std::array<int32_t, SIZE> refs{};

size_t usage = 0;
int usage = 0;

void free(Context& context, const void* ptr) {
const char* str = (const char*)(ptr);
Expand All @@ -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]);
Expand All @@ -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;
Expand All @@ -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];
}
Expand Down

0 comments on commit 8c1127b

Please sign in to comment.