Skip to content

Commit

Permalink
cleanups pt1
Browse files Browse the repository at this point in the history
  • Loading branch information
hjanetzek committed Nov 30, 2018
1 parent 788d41c commit 54ea946
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions core/src/js/DuktapeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,42 +630,30 @@ struct Context {
StringCache _stringCache;

static const char* jsExtstrInternCheck(void* udata, void* str, unsigned long blen) {
if (blen < 2) { return nullptr; } // TODO duk should have it's own small string cache!

if (blen > StringCache::entrybytes) {
LOG("[%p] >>>>> not my business %.*s - %d", str, blen, str, blen);
}

Context& context = *reinterpret_cast<Context*>(udata);
if (context._calling) {
//DBG("[%p / %p] >>>>> check %.*s - %d", str, context._lastPushed, blen, str, blen);
if (context._lastPushed == str) {
// We hold it - it's save!
// We hold it - safe!
DBGCACHE("[%p] >>>>> found %.*s - %d", str, blen, str, blen);
return context._lastPushed;
} else if (blen <= StringCache::entrybytes){


// context._buffer.replace(0, blen, (char*)str);
// auto ret = context._stringCache.emplace(context._buffer);
// if (!ret.second) {
// // todo could one stash the heapptr in this call?
// } else {
// context._allocCnt++;
// }
//LOG("[%p] >>>>> not mine %.*s - %d", str, blen, str, blen);
return context._stringCache.add(str, blen);
//return ret.first->data();
} else {
LOG("[%p] >>>>> not my business %.*s - %d", str, blen, str, blen);
// todo could one stash the heapptr in this call?
return context._stringCache.add(str, blen);
}
}
return nullptr;
}

static void jsExtstrFree(void* udata, const void *extdata) {
Context& context = *reinterpret_cast<Context*>(udata);

// context._freeCnt++;
//if (context._calling) {
//int pos =
context._stringCache.free(extdata);
//LOG("[%p] >>>>> free %d", extdata, pos); // (const char*)extdata);
//}
}

static cache_entry& getProperty(Context& context) {
Expand Down

0 comments on commit 54ea946

Please sign in to comment.