Preserve value references across arena relocation during array copies
This commit is contained in:
+14
-2
@@ -261,6 +261,8 @@ static sxi32 HashmapGrowBucket(ph7_hashmap *pMap) {
|
||||
*/
|
||||
static sxi32 HashmapInsertIntKey(ph7_hashmap *pMap, sxi64 iKey, ph7_value *pValue, sxu32 nRefIdx) {
|
||||
ph7_hashmap_node *pNode;
|
||||
sxu32 nValue = pValue ? pValue->nIdx : SXU32_HIGH;
|
||||
sxi32 bArena = pValue && SySetAt(&pMap->pVm->aMemObj, nValue) == pValue;
|
||||
sxu32 nIdx;
|
||||
sxu32 nHash;
|
||||
sxi32 rc;
|
||||
@@ -271,11 +273,15 @@ static sxi32 HashmapInsertIntKey(ph7_hashmap *pMap, sxi64 iKey, ph7_value *pValu
|
||||
if(pObj == 0) {
|
||||
return SXERR_MEM;
|
||||
}
|
||||
nIdx = pObj->nIdx;
|
||||
if(pValue) {
|
||||
/* Reserve may move the source slot as well as the new destination. */
|
||||
if(bArena) {
|
||||
pValue = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, nValue);
|
||||
}
|
||||
/* Duplicate the value */
|
||||
PH7_MemObjStore(pValue, pObj);
|
||||
}
|
||||
nIdx = pObj->nIdx;
|
||||
/* Hash the key */
|
||||
nHash = pMap->xIntHash(iKey);
|
||||
/* Allocate a new int node */
|
||||
@@ -302,6 +308,8 @@ static sxi32 HashmapInsertIntKey(ph7_hashmap *pMap, sxi64 iKey, ph7_value *pValu
|
||||
*/
|
||||
static sxi32 HashmapInsertBlobKey(ph7_hashmap *pMap, const void *pKey, sxu32 nKeyLen, ph7_value *pValue, sxu32 nRefIdx) {
|
||||
ph7_hashmap_node *pNode;
|
||||
sxu32 nValue = pValue ? pValue->nIdx : SXU32_HIGH;
|
||||
sxi32 bArena = pValue && SySetAt(&pMap->pVm->aMemObj, nValue) == pValue;
|
||||
sxu32 nHash;
|
||||
sxu32 nIdx;
|
||||
sxi32 rc;
|
||||
@@ -312,11 +320,15 @@ static sxi32 HashmapInsertBlobKey(ph7_hashmap *pMap, const void *pKey, sxu32 nKe
|
||||
if(pObj == 0) {
|
||||
return SXERR_MEM;
|
||||
}
|
||||
nIdx = pObj->nIdx;
|
||||
if(pValue) {
|
||||
/* Reserve may move the source slot as well as the new destination. */
|
||||
if(bArena) {
|
||||
pValue = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, nValue);
|
||||
}
|
||||
/* Duplicate the value */
|
||||
PH7_MemObjStore(pValue, pObj);
|
||||
}
|
||||
nIdx = pObj->nIdx;
|
||||
/* Hash the key */
|
||||
nHash = pMap->xBlobHash(pKey, nKeyLen);
|
||||
/* Allocate a new blob node */
|
||||
|
||||
Reference in New Issue
Block a user