You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by "afs (via GitHub)" <gi...@apache.org> on 2023/03/29 20:24:09 UTC

[GitHub] [jena] afs commented on a diff in pull request #1818: Misc

afs commented on code in PR #1818:
URL: https://github.com/apache/jena/pull/1818#discussion_r1152443056


##########
jena-arq/src/main/java/org/apache/jena/riot/out/NodeFmtLib.java:
##########
@@ -195,19 +198,24 @@ private static String displayStrNodes(Node...nodes) {
     // ---- Blank node labels.
 
     // Strict N-triples only allows [A-Za-z][A-Za-z0-9]
-    static char encodeMarkerChar = 'X';
+    private static final char encodeMarkerChar = 'X';
 
     // These two form a pair to convert bNode labels to a safe (i.e. legal N-triples form) and back again.
 
-    // Encoding is:
-    // 1 - Add a Letter
-    // 2 - Hexify, as Xnn, anything outside ASCII A-Za-z0-9
-    // 3 - X is encoded as XX
+    /**
+     *  Encoding is:
+     *  <ul>
+     *  <li> Add a start letter
+     *  <li> Hexify, as Xnn, anything outside ASCII A-Za-z0-9
+     *  <li> X is encoded as XX
+     */
 
-    private static char LabelLeadingLetter = 'B';
+    private static final char LabelLeadingLetter = 'B';
 
     public static String encodeBNodeLabel(String label) {
-        StringBuilder buff = new StringBuilder();
+        // A UUID string is 36 characters including 4 dashes.
+        // Together with the leading 'B', a total of 45 characters + any additional encoding needed.
+        StringBuilder buff = new StringBuilder(48);

Review Comment:
   The import thing is to avoid reallocation in the StringBuilder in common usage (UUID strings).
   
   Dashes get X-encoded so the overall is 45 -- a dash is "X2D".
   
   `878b5787-2c84-4624-a237-ad6fc35ec260`
   becomes 
   `B878b5787X2D2c84X2D4624X2Da237X2Dad6fc35ec260` which is 45.
   
   So the buffer must be >=45 for UUIDs.
   
   48 is a multiple of 8 (possible cache effect) and more than 45.
   
   The label isn't required to be a UUID.
   
   😄 
   



-- 
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: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org