-
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
Add primitive array setter optimization [Primitive Arrays Pt.4] #2312
base: develop
Are you sure you want to change the base?
Changes from all commits
a8a1f1d
7ba826e
29de359
dee84cb
92a60cf
1bc25e4
de28300
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import com.palantir.conjure.java.lib.SafeLong; | ||
import com.palantir.logsafe.Preconditions; | ||
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
|
@@ -140,11 +141,22 @@ public static <T> Set<T> newNonNullSet(Iterable<? extends T> iterable) { | |
return set; | ||
} | ||
|
||
/** | ||
* The following Conjure boxed list wrappers for the eclipse-collections [type]ArrayList are temporary (except | ||
* ConjureSafeLongList). In eclipse-collections 12, a BoxedMutable[type]List will be released. Once available, | ||
* Conjure[type]List should be replaced with that. | ||
*/ | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<Double> newNonNullDoubleList() { | ||
return new ConjureDoubleList(new DoubleArrayList()); | ||
} | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<Double> newNonNullDoubleList(double[] doubles) { | ||
return new ConjureDoubleList(DoubleArrayList.newListWith(doubles.clone())); | ||
} | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<Double> newNonNullDoubleList(Iterable<Double> iterable) { | ||
List<Double> doubleList; | ||
|
@@ -158,17 +170,16 @@ public static List<Double> newNonNullDoubleList(Iterable<Double> iterable) { | |
return doubleList; | ||
} | ||
|
||
/** | ||
* The following Conjure boxed list wrappers for the eclipse-collections [type]ArrayList are temporary (except | ||
* ConjureSafeLongList). In eclipse-collections 12, a BoxedMutable[type]List will be released. Once available, | ||
* Conjure[type]List should be replaced with that. | ||
*/ | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<Integer> newNonNullIntegerList() { | ||
return new ConjureIntegerList(new IntArrayList()); | ||
} | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<Integer> newNonNullIntegerList(int[] integers) { | ||
return new ConjureIntegerList(IntArrayList.newListWith(integers.clone())); | ||
} | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<Integer> newNonNullIntegerList(Iterable<Integer> iterable) { | ||
List<Integer> integerList; | ||
|
@@ -187,6 +198,11 @@ public static List<Boolean> newNonNullBooleanList() { | |
return new ConjureBooleanList(new BooleanArrayList()); | ||
} | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<Boolean> newNonNullBooleanList(boolean[] booleans) { | ||
return new ConjureBooleanList(BooleanArrayList.newListWith(booleans.clone())); | ||
} | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<Boolean> newNonNullBooleanList(Iterable<Boolean> iterable) { | ||
List<Boolean> booleanList; | ||
|
@@ -205,6 +221,19 @@ public static List<SafeLong> newNonNullSafeLongList() { | |
return new ConjureSafeLongList(new LongArrayList()); | ||
} | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<SafeLong> newNonNullSafeLongList(long[] longs) { | ||
long[] conjureCopy = longs.clone(); | ||
for (long value : conjureCopy) { | ||
if (!safeLongCheck(value)) { | ||
throw new SafeIllegalArgumentException( | ||
"number must be safely representable in javascript i.e. lie between -9007199254740991 and " | ||
+ "9007199254740991"); | ||
} | ||
} | ||
return new ConjureSafeLongList(LongArrayList.newListWith(conjureCopy)); | ||
} | ||
|
||
// This method returns a list that can't handle nulls. Do not use this unless the nonNullCollections flag is set | ||
public static List<SafeLong> newNonNullSafeLongList(Iterable<SafeLong> iterable) { | ||
List<SafeLong> safeLongList; | ||
|
@@ -217,4 +246,8 @@ public static List<SafeLong> newNonNullSafeLongList(Iterable<SafeLong> iterable) | |
|
||
return safeLongList; | ||
} | ||
|
||
private static boolean safeLongCheck(long value) { | ||
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. duplicated check from SafeLong. Not sure if its worth moving this to be public |
||
return SafeLong.MIN_VALUE.longValue() <= value && value <= SafeLong.MAX_VALUE.longValue(); | ||
} | ||
} |
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.
Oops don't know how I accidentally left the comment block down there :(