chaokunyang commented on code in PR #1892:
URL: https://github.com/apache/fury/pull/1892#discussion_r1811706292
##########
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);
Review Comment:
We'd better use
`org.apache.fury.meta.MetaStringEncoder#encode(java.lang.String)` instead, it
can get smaller encoded size for enum name than utf8 encoding
--
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]