chaokunyang commented on code in PR #1892:
URL: https://github.com/apache/fury/pull/1892#discussion_r1810002272
##########
java/fury-core/src/main/java/org/apache/fury/serializer/EnumSerializer.java:
##########
@@ -40,20 +50,54 @@ public EnumSerializer(Fury fury, Class<Enum> cls) {
Preconditions.checkArgument(enclosingClass.isEnum());
enumConstants = enclosingClass.getEnumConstants();
}
+
+ if (fury.getConfig().serializeEnumByName()) {
+ // as we know the size of enum is fixed, initialize the size of map with
that value
+ int initialCapacity = (int) Math.ceil(enumConstants.length / 0.99f);
+
+ metaStringtoEnumRepresentation = new HashMap<>(initialCapacity, 0.99f);
+
+ for (Enum enumConstant : enumConstants) {
+ if (enumConstant != null) {
+ MetaString ms =
+ Encoders.GENERIC_ENCODER.encode(enumConstant.name(),
MetaString.Encoding.UTF_8);
+ MetaStringBytes msb =
metaStringResolver.getOrCreateMetaStringBytes(ms);
+ metaStringtoEnumRepresentation.put(msb, enumConstant);
Review Comment:
We could also create an array `MetaStringBytes[]` whose index are enum
oridinal
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]