@@ -303,21 +303,20 @@ static LocationImpl getLocation(Property existing) {
303303 }
304304
305305 @ 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 ) {
309307 if (existingProperty == null && Flags .isSetExisting (putFlags )) {
310308 return false ;
311309 }
312310 if (existingProperty != null && !Flags .isUpdateFlags (putFlags ) && existingProperty .getLocation ().canStore (value )) {
313311 getLocation (existingProperty ).setSafe (object , value , false , false );
314312 return true ;
315313 } else {
316- return putUncachedSlow (object , key , value , newPropertyFlags , putFlags );
314+ return putGenericSlowPath (object , key , value , newPropertyFlags , putFlags , s , existingProperty );
317315 }
318316 }
319317
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 ) {
321320 CompilerAsserts .neverPartOfCompilation ();
322321 updateShapeImpl (object );
323322 Shape oldShape ;
@@ -326,7 +325,11 @@ private static boolean putUncachedSlow(DynamicObject object, Object key, Object
326325 Property property ;
327326 do {
328327 oldShape = object .getShape ();
329- existingProperty = oldShape .getProperty (key );
328+ if (oldShape == initialShape ) {
329+ existingProperty = propertyOfInitialShape ;
330+ } else {
331+ existingProperty = oldShape .getProperty (key );
332+ }
330333 if (existingProperty == null ) {
331334 if (Flags .isSetExisting (putFlags )) {
332335 return false ;
@@ -720,7 +723,7 @@ public double getDoubleOrDefault(DynamicObject object, Shape cachedShape, Object
720723
721724 @ Override
722725 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 ) );
724727 }
725728
726729 @ Override
@@ -1297,7 +1300,7 @@ protected boolean putImpl(DynamicObject object, Shape cachedShape, Object key, O
12971300 Shape oldShape = cachedShape ;
12981301 MutateCacheData start = cache ;
12991302 if (start == MutateCacheData .GENERIC || !cachedShape .isValid ()) {
1300- return putUncached (object , key , value , propertyFlags , putFlags );
1303+ return putGeneric (object , key , value , propertyFlags , putFlags , cachedShape , oldProperty );
13011304 }
13021305 for (MutateCacheData c = start ; c != null ; c = c .next ) {
13031306 if (!c .isValid ()) {
@@ -1335,7 +1338,7 @@ protected boolean putIntImpl(DynamicObject object, Shape cachedShape, Object key
13351338 Shape oldShape = cachedShape ;
13361339 MutateCacheData start = cache ;
13371340 if (start == MutateCacheData .GENERIC || !cachedShape .isValid ()) {
1338- return putUncached (object , key , value , propertyFlags , putFlags );
1341+ return putGeneric (object , key , value , propertyFlags , putFlags , cachedShape , oldProperty );
13391342 }
13401343 for (MutateCacheData c = start ; c != null ; c = c .next ) {
13411344 if (!c .isValid ()) {
@@ -1403,7 +1406,7 @@ protected boolean putLongImpl(DynamicObject object, Shape cachedShape, Object ke
14031406 Shape oldShape = cachedShape ;
14041407 MutateCacheData start = cache ;
14051408 if (start == MutateCacheData .GENERIC ) {
1406- return putUncached (object , key , value , propertyFlags , putFlags );
1409+ return putGeneric (object , key , value , propertyFlags , putFlags , cachedShape , oldProperty );
14071410 }
14081411 for (MutateCacheData c = start ; c != null ; c = c .next ) {
14091412 if (!c .isValid ()) {
@@ -1452,7 +1455,7 @@ protected boolean putDoubleImpl(DynamicObject object, Shape cachedShape, Object
14521455 Shape oldShape = cachedShape ;
14531456 MutateCacheData start = cache ;
14541457 if (start == MutateCacheData .GENERIC ) {
1455- return putUncached (object , key , value , propertyFlags , putFlags );
1458+ return putGeneric (object , key , value , propertyFlags , putFlags , cachedShape , oldProperty );
14561459 }
14571460 for (MutateCacheData c = start ; c != null ; c = c .next ) {
14581461 if (!c .isValid ()) {
0 commit comments