@@ -60,6 +60,7 @@ public static DynamicObject create(RubyContext context, Collection<KeyValue> ent
60
60
61
61
final int index = BucketsStrategy .getBucketIndex (hashed , newEntries .length );
62
62
Entry bucketEntry = newEntries [index ];
63
+ boolean duplicateKey = false ;
63
64
64
65
if (bucketEntry == null ) {
65
66
newEntries [index ] = newEntry ;
@@ -72,47 +73,33 @@ && areKeysEqual(context, bucketEntry.getKey(), key, byIdentity)) {
72
73
bucketEntry .setValue (entry .getValue ());
73
74
74
75
actualSize --;
75
-
76
- if (bucketEntry .getPreviousInSequence () != null ) {
77
- bucketEntry .getPreviousInSequence ().setNextInSequence (bucketEntry .getNextInSequence ());
78
- }
79
-
80
- if (bucketEntry .getNextInSequence () != null ) {
81
- bucketEntry .getNextInSequence ().setPreviousInSequence (bucketEntry .getPreviousInSequence ());
82
- }
83
-
84
- if (bucketEntry == lastInSequence ) {
85
- lastInSequence = bucketEntry .getPreviousInSequence ();
86
- }
87
-
88
- // We wasted by allocating newEntry, but never mind
89
- newEntry = bucketEntry ;
90
- previousInBucket = null ;
91
-
76
+ duplicateKey = true ;
92
77
break ;
93
78
}
94
79
95
80
previousInBucket = bucketEntry ;
96
81
bucketEntry = bucketEntry .getNextInLookup ();
97
82
}
98
83
99
- if (previousInBucket != null ) {
84
+ if (! duplicateKey && previousInBucket != null ) {
100
85
previousInBucket .setNextInLookup (newEntry );
101
86
}
102
87
}
103
88
104
- if (firstInSequence == null ) {
105
- firstInSequence = newEntry ;
106
- }
89
+ if (!duplicateKey ) {
90
+ if (firstInSequence == null ) {
91
+ firstInSequence = newEntry ;
92
+ }
107
93
108
- if (lastInSequence != null ) {
109
- lastInSequence .setNextInSequence (newEntry );
110
- }
94
+ if (lastInSequence != null ) {
95
+ lastInSequence .setNextInSequence (newEntry );
96
+ }
111
97
112
- newEntry .setPreviousInSequence (lastInSequence );
113
- newEntry .setNextInSequence (null );
98
+ newEntry .setPreviousInSequence (lastInSequence );
99
+ newEntry .setNextInSequence (null );
114
100
115
- lastInSequence = newEntry ;
101
+ lastInSequence = newEntry ;
102
+ }
116
103
}
117
104
118
105
final DynamicObject nil = context .getCoreLibrary ().getNil ();
0 commit comments