Skip to content

Commit 2e2cb35

Browse files
committed
Minor perf tweak for PropertySerializerMap.Multi
1 parent 799da54 commit 2e2cb35

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/impl/PropertySerializerMap.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,32 @@ public Multi(PropertySerializerMap base, TypeAndSerializer[] entries) {
349349
@Override
350350
public JsonSerializer<Object> serializerFor(Class<?> type)
351351
{
352-
for (int i = 0, len = _entries.length; i < len; ++i) {
353-
TypeAndSerializer entry = _entries[i];
354-
if (entry.type == type) {
355-
return entry.serializer;
356-
}
352+
// Always have first 3 populated so
353+
TypeAndSerializer entry;
354+
entry = _entries[0];
355+
if (entry.type == type) return entry.serializer;
356+
entry = _entries[1];
357+
if (entry.type == type) return entry.serializer;
358+
entry = _entries[2];
359+
if (entry.type == type) return entry.serializer;
360+
361+
switch (_entries.length) {
362+
case 8:
363+
entry = _entries[7];
364+
if (entry.type == type) return entry.serializer;
365+
case 7:
366+
entry = _entries[6];
367+
if (entry.type == type) return entry.serializer;
368+
case 6:
369+
entry = _entries[5];
370+
if (entry.type == type) return entry.serializer;
371+
case 5:
372+
entry = _entries[4];
373+
if (entry.type == type) return entry.serializer;
374+
case 4:
375+
entry = _entries[3];
376+
if (entry.type == type) return entry.serializer;
377+
default:
357378
}
358379
return null;
359380
}

0 commit comments

Comments
 (0)