This content has been marked as final.
Show 2 replies
-
1. Re: JBVFS-26 - Optimizing the VFS PathTokenizer
alesj May 21, 2008 5:36 AM (in response to adrian.brock)OK, I'll look into both, 1) and 2).
Should be included in the next VFS version. -
2. Re: JBVFS-26 - Optimizing the VFS PathTokenizer
alesj May 22, 2008 7:38 AM (in response to adrian.brock)"adrian@jboss.org" wrote:
1) If StringTokenizer was replaced with an optimized lexer
(e.g. like the one used to parse system property references from strings in common-core)
then the check for an empty token could be done inline instead of string
comparison.
This is now rewritten into this:public static String[] getTokens(String path) { if (path == null) throw new IllegalArgumentException("Null path"); char[] chars = path.toCharArray(); StringBuilder buffer = new StringBuilder(); List<String> list = new ArrayList<String>(); String specialToken = null; for (int index=0; index < chars.length; index++) { char ch = chars[index]; if (ch == '/') { if (index > 0) { if (buffer.length() == 0 && specialToken == null) throw new IllegalArgumentException("A path element is empty: " + path); if (specialToken != null) list.add(specialToken); else list.add(buffer.toString()); // reset buffer.setLength(0); specialToken = null; } } else if (ch == '.') { if (specialToken == null && buffer.length() == 0) specialToken = CURRENT_PATH; else if (specialToken == CURRENT_PATH && buffer.length() == 0) specialToken = REVERSE_PATH; else if (specialToken != null && buffer.length() == 0) throw new IllegalArgumentException("Illegal token in path: " + path); else buffer.append(ch); } else { // token starts with '.' or '..', but also has some path after that if (specialToken != null) throw new IllegalArgumentException("Illegal token in path: " + path); buffer.append(ch); } } // add last token if (specialToken != null) list.add(specialToken); else if (buffer.length() > 0) list.add(buffer.toString()); return list.toArray(new String[list.size()]); }
and we do '==' check on special tokens. ;-)