Skip to content

Commit 5646c93

Browse files
committed
Undo hashCode improvement: while giving better spread, not faster (possibly mildly slower)
1 parent 84e64c2 commit 5646c93

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/impl/BeanPropertyMap.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public BeanPropertyMap renameAll(NameTransformer transformer)
8585
}
8686

8787
protected abstract BeanPropertyMap _renameAll(NameTransformer transformer);
88-
88+
8989
// Confining this case insensitivity to this function (and the find method) in case we want to
9090
// apply a particular locale to the lower case function. For now, using the default.
9191
protected final String getPropertyName(SettableBeanProperty prop) {
@@ -276,11 +276,11 @@ protected Small(boolean caseInsensitive, int sz,
276276
super(caseInsensitive);
277277
size = sz;
278278
prop1 = p1;
279-
key1 = (p1 == null) ? null : p1.getName();
279+
key1 = (p1 == null) ? null : getPropertyName(p1);
280280
prop2 = p2;
281-
key2 = (p2 == null) ? null : p2.getName();
281+
key2 = (p2 == null) ? null : getPropertyName(p2);
282282
prop3 = p3;
283-
key3 = (p3 == null) ? null : p3.getName();
283+
key3 = (p3 == null) ? null : getPropertyName(p3);
284284
}
285285

286286
@Override
@@ -298,7 +298,7 @@ protected BeanPropertyMap _renameAll(NameTransformer transformer)
298298
@Override
299299
public BeanPropertyMap withProperty(SettableBeanProperty prop)
300300
{
301-
final String key = prop.getName();
301+
final String key = getPropertyName(prop);
302302
// First: replace existing one?
303303
switch (size) {
304304
case 3:
@@ -390,6 +390,9 @@ public int size() {
390390

391391
@Override
392392
public SettableBeanProperty find(String key) {
393+
if (_caseInsensitive) {
394+
key = key.toLowerCase();
395+
}
393396
if (key == key1) return prop1;
394397
if (key == key2) return prop2;
395398
if (key == key3) return prop3;
@@ -543,6 +546,7 @@ protected void init(Collection<SettableBeanProperty> props)
543546
}
544547

545548
String key = getPropertyName(prop);
549+
// int slot = _hashCode(key);
546550
int slot = key.hashCode() & _hashMask;
547551

548552
// primary slot not free?
@@ -559,15 +563,16 @@ protected void init(Collection<SettableBeanProperty> props)
559563
}
560564
}
561565
}
562-
//System.err.println(" add '"+key+" at #"+slot+" (hashed at "+(key.hashCode() & _hashMask)+")");
566+
//System.err.println(" add '"+key+" at #"+slot+"/"+size+" (hashed at "+_hashCode(key)+")");
563567
keys[slot] = key;
564568
propHash[slot] = prop;
565569
}
566-
/*
570+
/*
567571
for (int i = 0; i < keys.length; ++i) {
568572
System.err.printf("#%02d: %s\n", i, (keys[i] == null) ? "-" : keys[i]);
569573
}
570574
*/
575+
571576
_keys = keys;
572577
_propsHash = propHash;
573578
_spillCount = spills;
@@ -625,7 +630,9 @@ public BeanPropertyMap withProperty(SettableBeanProperty newProp)
625630
}
626631
// If not, append
627632

633+
// int slot = _hashCode(key);
628634
int slot = key.hashCode() & _hashMask;
635+
629636
int hashSize = _hashMask+1;
630637

631638
// primary slot not free?
@@ -753,6 +760,7 @@ public SettableBeanProperty find(String key)
753760
if (_caseInsensitive) {
754761
key = key.toLowerCase();
755762
}
763+
// int slot = _hashCode(key);
756764
int slot = key.hashCode() & _hashMask;
757765
String match = _keys[slot];
758766
if ((match == key) || key.equals(match)) {
@@ -807,5 +815,13 @@ private int _findFromOrdered(SettableBeanProperty prop) {
807815
}
808816
throw new IllegalStateException("Illegal state: property '"+prop.getName()+"' missing from _propsInOrder");
809817
}
818+
819+
/*
820+
private final int _hashCode(String key) {
821+
int h = key.hashCode();
822+
h ^= h >> 13;
823+
return h & _hashMask;
824+
}
825+
*/
810826
}
811827
}

0 commit comments

Comments
 (0)