[jboss-dev-forums] [Design of POJO Server] - Re: JBVFS-26 - Optimizing the VFS PathTokenizer
alesj
do-not-reply at jboss.com
Thu May 22 07:39:00 EDT 2008
"adrian at 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
| buffer.append(ch);
| }
| else
| {
| 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. ;-)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4152637#4152637
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4152637
More information about the jboss-dev-forums
mailing list