keith-turner commented on code in PR #4563:
URL: https://github.com/apache/accumulo/pull/4563#discussion_r1605339033


##########
core/src/main/java/org/apache/accumulo/core/util/UuidUtil.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.util;
+
+public class UuidUtil {
+  private static boolean isHex(String s, int offset, int start, int end) {
+    for (int i = start; i < end; i++) {
+      var c = s.charAt(i + offset);
+      boolean isHex = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c 
>= 'A' && c <= 'F');
+      if (!isHex) {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  /**
+   * A fast method for verifying a suffix of a string looks like a uuid.
+   *
+   * @param offset location where the uuid starts. Its expected the uuid 
occupies the rest of the
+   *        string.
+   */
+  public static boolean isUUID(String uuid, int offset) {
+    return uuid.length() - offset == 36 && isHex(uuid, offset, 0, 8)
+        && uuid.charAt(8 + offset) == '-' && isHex(uuid, offset, 9, 13)
+        && uuid.charAt(13 + offset) == '-' && isHex(uuid, offset, 14, 18)
+        && uuid.charAt(18 + offset) == '-' && isHex(uuid, offset, 19, 23)
+        && uuid.charAt(23 + offset) == '-' && isHex(uuid, offset, 24, 36);

Review Comment:
   It looks like it would be faster. Its doing a bit more work per character in 
the loop, but its not doing all of the function calls. I don't think I could 
discern any different with the profiling testing I have been doing, both impls 
are probably orders of magnitude times faster than the regex and neither will 
show up in the profiling data like the regex did.
   
   I can give it a try, I think it just needs a few comments.



-- 
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]

Reply via email to