com.signalfx.shaded.fasterxml.jackson.databind.ser.impl.ReadOnlyClassToSerializerMap Maven / Gradle / Ivy
Show all versions of signalfx-codahale Show documentation
package com.signalfx.shaded.fasterxml.jackson.databind.ser.impl;
import com.signalfx.shaded.fasterxml.jackson.databind.JavaType;
import com.signalfx.shaded.fasterxml.jackson.databind.JsonSerializer;
import com.signalfx.shaded.fasterxml.jackson.databind.util.LookupCache;
import com.signalfx.shaded.fasterxml.jackson.databind.util.TypeKey;
/**
* Optimized lookup table for accessing two types of serializers; typed
* and non-typed. Only accessed from a single thread, so no synchronization
* needed for accessors.
*
* Note that before 2.6 this class was much smaller, and referred most
* operations to separate JsonSerializerMap
, but in 2.6
* functions were combined.
*/
public final class ReadOnlyClassToSerializerMap
{
private final Bucket[] _buckets;
private final int _size;
private final int _mask;
public ReadOnlyClassToSerializerMap(LookupCache> src)
{
_size = findSize(src.size());
_mask = (_size-1);
Bucket[] buckets = new Bucket[_size];
src.contents((key, value) -> {
int index = key.hashCode() & _mask;
buckets[index] = new Bucket(buckets[index], key, value);
});
_buckets = buckets;
}
private final static int findSize(int size)
{
// For small enough results (64 or less), we'll require <= 50% fill rate; otherwise 80%
int needed = (size <= 64) ? (size + size) : (size + (size >> 2));
int result = 8;
while (result < needed) {
result += result;
}
return result;
}
/**
* Factory method for constructing an instance.
*/
public static ReadOnlyClassToSerializerMap from(LookupCache> src) {
return new ReadOnlyClassToSerializerMap(src);
}
/*
/**********************************************************
/* Public API
/**********************************************************
*/
public int size() { return _size; }
public JsonSerializer