-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add Serialization Optimization for Primitive Collection Types #2386
base: bmarcaurele/small-conjure-collections-refactor
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type: improvement | ||
improvement: | ||
description: '[FR] Add Serialization Optimization for Primitive Collection Types' | ||
links: | ||
- https://github.com/palantir/conjure-java/pull/2386 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
types: | ||
definitions: | ||
default-package: com.palantir.product | ||
objects: | ||
PrimitiveExample: | ||
fields: | ||
ints: list<integer> | ||
doubles: list<double> | ||
longs: list<safelong> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,21 @@ | |
|
||
package com.palantir.conjure.java.lib.internal; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import java.util.AbstractList; | ||
import java.util.Collection; | ||
import java.util.RandomAccess; | ||
import org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList; | ||
import org.eclipse.collections.api.list.primitive.MutableDoubleList; | ||
import org.eclipse.collections.impl.utility.Iterate; | ||
|
||
/** | ||
* ConjureDoubleList is a boxed list wrapper for the eclipse-collections DoubleArrayList. In eclipse-collections 12, | ||
* a BoxedMutableDoubleList will be released. Once available, ConjureDoubleList should be replaced with that. | ||
*/ | ||
final class ConjureDoubleList extends AbstractList<Double> implements RandomAccess { | ||
private final DoubleArrayList delegate; | ||
private final MutableDoubleList delegate; | ||
|
||
ConjureDoubleList(DoubleArrayList delegate) { | ||
ConjureDoubleList(MutableDoubleList delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
|
@@ -69,4 +70,15 @@ public void clear() { | |
public Double set(int index, Double element) { | ||
return delegate.set(index, element); | ||
} | ||
|
||
public ConjureDoubleList asUnmodifiable() { | ||
return new ConjureDoubleList(delegate.asUnmodifiable()); | ||
} | ||
|
||
// Cannot be named 'toArray' as that conflicts with the #toArray in AbstractList | ||
// This is a serialization optimization that avoids boxing, but does copy | ||
@JsonValue | ||
double[] jacksonSerialize() { | ||
return delegate.toArray(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how we avoid boxing out the door (I checked the Jackson code paths manually, it does infact operate on the array), while also respecting the various Jackson flags we use like |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this type so that I can wrap both
DoubleArrayList
andUnmodifiableDoubleList
which share this interface as the lowest common denominator.