netudima commented on code in PR #4530:
URL: https://github.com/apache/cassandra/pull/4530#discussion_r2624886499
##########
src/java/org/apache/cassandra/serializers/UTF8Serializer.java:
##########
@@ -57,8 +60,51 @@ static <V> boolean validate(V value, ValueAccessor<V>
accessor)
if (value == null)
return false;
- int b = 0;
- int offset = 0;
+ // perf optimizations:
+ // 1) avoid bymorhic/megamorphic calls via ValueAccessor
+ // 2) use a simplified logic to handle ASCII prefixed String
scenario faster
+ if (accessor == ByteArrayAccessor.instance)
+ {
+ byte[] valueAsArray = accessor.toArray(value);
+ for (int i = 0; i < valueAsArray.length; i++)
+ {
+ if (valueAsArray[i] < 0)
+ return validateSlowPath(value, accessor, i);
+ }
+ return true;
+ }
+
+ if (accessor == ByteBufferAccessor.instance)
+ {
+ ByteBuffer valueAsBuffer = accessor.toBuffer(value);
+ if (valueAsBuffer.hasArray())
+ {
+ byte[] valueAsArray = valueAsBuffer.array();
+ int start = valueAsBuffer.position();
+ int end = start + valueAsBuffer.remaining();
+ for (int i = start; i < end; i++)
+ {
+ if (valueAsArray[i] < 0)
+ return validateSlowPath(value, accessor, i -
start);
+ }
+ }
+ return true;
Review Comment:
thank you for highlighting the issue
--
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]