@@ -303,21 +303,20 @@ static LocationImpl getLocation(Property existing) {
303
303
}
304
304
305
305
@ TruffleBoundary
306
- protected static boolean putUncached (DynamicObject object , Object key , Object value , int newPropertyFlags , int putFlags ) {
307
- Shape s = object .getShape ();
308
- Property existingProperty = s .getProperty (key );
306
+ protected static boolean putGeneric (DynamicObject object , Object key , Object value , int newPropertyFlags , int putFlags , Shape s , Property existingProperty ) {
309
307
if (existingProperty == null && Flags .isSetExisting (putFlags )) {
310
308
return false ;
311
309
}
312
310
if (existingProperty != null && !Flags .isUpdateFlags (putFlags ) && existingProperty .getLocation ().canStore (value )) {
313
311
getLocation (existingProperty ).setSafe (object , value , false , false );
314
312
return true ;
315
313
} else {
316
- return putUncachedSlow (object , key , value , newPropertyFlags , putFlags );
314
+ return putGenericSlowPath (object , key , value , newPropertyFlags , putFlags , s , existingProperty );
317
315
}
318
316
}
319
317
320
- private static boolean putUncachedSlow (DynamicObject object , Object key , Object value , int newPropertyFlags , int putFlags ) {
318
+ private static boolean putGenericSlowPath (DynamicObject object , Object key , Object value , int newPropertyFlags , int putFlags ,
319
+ Shape initialShape , Property propertyOfInitialShape ) {
321
320
CompilerAsserts .neverPartOfCompilation ();
322
321
updateShapeImpl (object );
323
322
Shape oldShape ;
@@ -326,7 +325,11 @@ private static boolean putUncachedSlow(DynamicObject object, Object key, Object
326
325
Property property ;
327
326
do {
328
327
oldShape = object .getShape ();
329
- existingProperty = oldShape .getProperty (key );
328
+ if (oldShape == initialShape ) {
329
+ existingProperty = propertyOfInitialShape ;
330
+ } else {
331
+ existingProperty = oldShape .getProperty (key );
332
+ }
330
333
if (existingProperty == null ) {
331
334
if (Flags .isSetExisting (putFlags )) {
332
335
return false ;
@@ -720,7 +723,7 @@ public double getDoubleOrDefault(DynamicObject object, Shape cachedShape, Object
720
723
721
724
@ Override
722
725
public boolean put (DynamicObject object , Shape cachedShape , Object key , Object value , int propertyFlags , int putFlags ) {
723
- return putUncached (object , key , value , propertyFlags , putFlags );
726
+ return putGeneric (object , key , value , propertyFlags , putFlags , cachedShape , cachedShape . getProperty ( key ) );
724
727
}
725
728
726
729
@ Override
@@ -1297,7 +1300,7 @@ protected boolean putImpl(DynamicObject object, Shape cachedShape, Object key, O
1297
1300
Shape oldShape = cachedShape ;
1298
1301
MutateCacheData start = cache ;
1299
1302
if (start == MutateCacheData .GENERIC || !cachedShape .isValid ()) {
1300
- return putUncached (object , key , value , propertyFlags , putFlags );
1303
+ return putGeneric (object , key , value , propertyFlags , putFlags , cachedShape , oldProperty );
1301
1304
}
1302
1305
for (MutateCacheData c = start ; c != null ; c = c .next ) {
1303
1306
if (!c .isValid ()) {
@@ -1335,7 +1338,7 @@ protected boolean putIntImpl(DynamicObject object, Shape cachedShape, Object key
1335
1338
Shape oldShape = cachedShape ;
1336
1339
MutateCacheData start = cache ;
1337
1340
if (start == MutateCacheData .GENERIC || !cachedShape .isValid ()) {
1338
- return putUncached (object , key , value , propertyFlags , putFlags );
1341
+ return putGeneric (object , key , value , propertyFlags , putFlags , cachedShape , oldProperty );
1339
1342
}
1340
1343
for (MutateCacheData c = start ; c != null ; c = c .next ) {
1341
1344
if (!c .isValid ()) {
@@ -1403,7 +1406,7 @@ protected boolean putLongImpl(DynamicObject object, Shape cachedShape, Object ke
1403
1406
Shape oldShape = cachedShape ;
1404
1407
MutateCacheData start = cache ;
1405
1408
if (start == MutateCacheData .GENERIC ) {
1406
- return putUncached (object , key , value , propertyFlags , putFlags );
1409
+ return putGeneric (object , key , value , propertyFlags , putFlags , cachedShape , oldProperty );
1407
1410
}
1408
1411
for (MutateCacheData c = start ; c != null ; c = c .next ) {
1409
1412
if (!c .isValid ()) {
@@ -1452,7 +1455,7 @@ protected boolean putDoubleImpl(DynamicObject object, Shape cachedShape, Object
1452
1455
Shape oldShape = cachedShape ;
1453
1456
MutateCacheData start = cache ;
1454
1457
if (start == MutateCacheData .GENERIC ) {
1455
- return putUncached (object , key , value , propertyFlags , putFlags );
1458
+ return putGeneric (object , key , value , propertyFlags , putFlags , cachedShape , oldProperty );
1456
1459
}
1457
1460
for (MutateCacheData c = start ; c != null ; c = c .next ) {
1458
1461
if (!c .isValid ()) {
0 commit comments