@@ -242,16 +242,17 @@ public BeanPropertyMap renameAll(NameTransformer transformer)
242
242
public void replace (SettableBeanProperty newProp )
243
243
{
244
244
String key = getPropertyName (newProp );
245
- for ( int i = 1 , end = _hashArea . length ; i < end ; i += 2 ) {
246
- SettableBeanProperty prop = ( SettableBeanProperty ) _hashArea [ i ];
247
- if (( prop != null ) && prop . getName (). equals ( key ) ) {
248
- _hashArea [i ] = newProp ;
249
- // also, replace in in-order
250
- _propsInOrder [ _findFromOrdered ( prop )] = newProp ;
251
- return ;
252
- }
245
+ int ix = _findIndexInHash ( key );
246
+
247
+ if (ix >= 0 ) {
248
+ SettableBeanProperty prop = ( SettableBeanProperty ) _hashArea [ix ] ;
249
+ _hashArea [ ix ] = newProp ;
250
+ // also, replace in in-order
251
+ _propsInOrder [ _findFromOrdered ( prop )] = newProp ;
252
+ return ;
253
253
}
254
- throw new NoSuchElementException ("No entry '" +newProp .getName ()+"' found, can't replace" );
254
+
255
+ throw new NoSuchElementException ("No entry '" +key +"' found, can't replace" );
255
256
}
256
257
257
258
private List <SettableBeanProperty > properties () {
@@ -296,6 +297,8 @@ protected final String getPropertyName(SettableBeanProperty prop) {
296
297
*/
297
298
public SettableBeanProperty find (int index )
298
299
{
300
+ // note: will scan the whole area, including primary, secondary and
301
+ // possible spill-area
299
302
for (int i = 1 , end = _hashArea .length ; i < end ; i += 2 ) {
300
303
SettableBeanProperty prop = (SettableBeanProperty ) _hashArea [i ];
301
304
if ((prop != null ) && (index == prop .getPropertyIndex ())) {
@@ -486,7 +489,40 @@ protected void wrapAndThrow(Throwable t, Object bean, String fieldName, Deserial
486
489
throw JsonMappingException .wrapWithPath (t , bean , fieldName );
487
490
}
488
491
489
- private int _findFromOrdered (SettableBeanProperty prop ) {
492
+ /**
493
+ * Helper method used to find exact location of a property with name
494
+ * given exactly, not subject to case changes, within hash area.
495
+ * Expectation is that such property SHOULD exist, although no
496
+ * exception is thrown.
497
+ *
498
+ * @since 2.7
499
+ */
500
+ private final int _findIndexInHash (String key )
501
+ {
502
+ final int slot = _hashCode (key );
503
+ int ix = (slot <<1 );
504
+
505
+ // primary match?
506
+ if (key .equals (_hashArea [ix ])) {
507
+ return ix +1 ;
508
+ }
509
+ // no? secondary?
510
+ int hashSize = _hashMask +1 ;
511
+ ix = hashSize + (slot >>1 ) << 1 ;
512
+ if (key .equals (_hashArea [ix ])) {
513
+ return ix +1 ;
514
+ }
515
+ // perhaps spill then
516
+ int i = (hashSize + (hashSize >>1 )) << 1 ;
517
+ for (int end = i + _spillCount ; i < end ; i += 2 ) {
518
+ if (key .equals (_hashArea [i ])) {
519
+ return i +1 ;
520
+ }
521
+ }
522
+ return -1 ;
523
+ }
524
+
525
+ private final int _findFromOrdered (SettableBeanProperty prop ) {
490
526
for (int i = 0 , end = _propsInOrder .length ; i < end ; ++i ) {
491
527
if (_propsInOrder [i ] == prop ) {
492
528
return i ;
0 commit comments