mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-05 08:10:05 +00:00
smarter caching
This commit is contained in:
parent
181ef8a18c
commit
b1facfc92f
@ -211,6 +211,7 @@ CObjString *cosmoO_takeString(CState *state, char *str, size_t sz) {
|
|||||||
|
|
||||||
CObjString *cosmoO_allocateString(CState *state, const char *str, size_t sz, uint32_t hash) {
|
CObjString *cosmoO_allocateString(CState *state, const char *str, size_t sz, uint32_t hash) {
|
||||||
CObjString *strObj = (CObjString*)cosmoO_allocateBase(state, sizeof(CObjString), COBJ_STRING);
|
CObjString *strObj = (CObjString*)cosmoO_allocateBase(state, sizeof(CObjString), COBJ_STRING);
|
||||||
|
strObj->isIString = false;
|
||||||
strObj->str = (char*)str;
|
strObj->str = (char*)str;
|
||||||
strObj->length = sz;
|
strObj->length = sz;
|
||||||
strObj->hash = hash;
|
strObj->hash = hash;
|
||||||
@ -254,7 +255,10 @@ void cosmoO_setObject(CState *state, CObjObject *object, CValue key, CValue val)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the key is an IString, we need to reset the cache
|
||||||
|
if (IS_STRING(key) && ((CObjString*)cosmoV_readObj(key))->isIString)
|
||||||
object->istringFlags = 0; // reset cache
|
object->istringFlags = 0; // reset cache
|
||||||
|
|
||||||
if (IS_NIL(val)) { // if we're setting an index to nil, we can safely mark that as a tombstone
|
if (IS_NIL(val)) { // if we're setting an index to nil, we can safely mark that as a tombstone
|
||||||
cosmoT_remove(state, &object->tbl, key);
|
cosmoT_remove(state, &object->tbl, key);
|
||||||
} else {
|
} else {
|
||||||
|
@ -37,6 +37,7 @@ typedef struct CObj {
|
|||||||
|
|
||||||
typedef struct CObjString {
|
typedef struct CObjString {
|
||||||
CommonHeader; // "is a" CObj
|
CommonHeader; // "is a" CObj
|
||||||
|
bool isIString;
|
||||||
int length;
|
int length;
|
||||||
char *str;
|
char *str;
|
||||||
uint32_t hash; // for hashtable lookup
|
uint32_t hash; // for hashtable lookup
|
||||||
|
@ -49,6 +49,10 @@ CState *cosmoV_newState() {
|
|||||||
state->iStrings[ISTRING_GETTER] = cosmoO_copyString(state, "__getter", 8);
|
state->iStrings[ISTRING_GETTER] = cosmoO_copyString(state, "__getter", 8);
|
||||||
state->iStrings[ISTRING_SETTER] = cosmoO_copyString(state, "__setter", 8);
|
state->iStrings[ISTRING_SETTER] = cosmoO_copyString(state, "__setter", 8);
|
||||||
|
|
||||||
|
// set the IString flags
|
||||||
|
for (int i = 0; i < ISTRING_MAX; i++)
|
||||||
|
state->iStrings[i]->isIString = true;
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ typedef struct CCallFrame {
|
|||||||
|
|
||||||
typedef enum IStringEnum {
|
typedef enum IStringEnum {
|
||||||
ISTRING_INIT, // __init
|
ISTRING_INIT, // __init
|
||||||
ISTRING_EQUAL, // __equal
|
|
||||||
ISTRING_INDEX, // __index
|
ISTRING_INDEX, // __index
|
||||||
ISTRING_NEWINDEX, // __newindex
|
ISTRING_NEWINDEX, // __newindex
|
||||||
ISTRING_GETTER, // __getter
|
ISTRING_GETTER, // __getter
|
||||||
|
Loading…
Reference in New Issue
Block a user