--- old/src/solaris/classes/java/io/UnixFileSystem.java 2013-02-15 20:20:23.424712663 -0800 +++ new/src/solaris/classes/java/io/UnixFileSystem.java 2013-02-15 20:20:23.060712672 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -55,42 +55,30 @@ return colon; } - /* A normal Unix pathname contains no duplicate slashes and does not end - with a slash. It may be the empty string. */ - - /* Normalize the given pathname, whose length is len, starting at the given - offset; everything before this offset is already normal. */ - private String normalize(String pathname, int len, int off) { - if (len == 0) return pathname; - int n = len; - while ((n > 0) && (pathname.charAt(n - 1) == '/')) n--; - if (n == 0) return "/"; - StringBuffer sb = new StringBuffer(pathname.length()); - if (off > 0) sb.append(pathname.substring(0, off)); + /* + * A normal Unix path name contains no duplicate slashes and does not end + * with a slash. It may be the empty string. Check and normalize the + * given pathname. The whole pathname string is only iterated once. + */ + @Override + public String normalize(String pathname) { + final int len = pathname.length(); + StringBuilder sb = new StringBuilder(len); char prevChar = 0; - for (int i = off; i < n; i++) { + + for (int i = 0; i < len; i++) { char c = pathname.charAt(i); + if (c == CHAR_NUL) continue; if ((prevChar == '/') && (c == '/')) continue; + sb.append(c); prevChar = c; } - return sb.toString(); - } - /* Check that the given pathname is normal. If not, invoke the real - normalizer on the part of the pathname that requires normalization. - This way we iterate through the whole pathname string only once. */ - public String normalize(String pathname) { - int n = pathname.length(); - char prevChar = 0; - for (int i = 0; i < n; i++) { - char c = pathname.charAt(i); - if ((prevChar == '/') && (c == '/')) - return normalize(pathname, n, i - 1); - prevChar = c; - } - if (prevChar == '/') return normalize(pathname, n, n - 1); - return pathname; + if (prevChar == '/' && sb.length() > 1) + sb.setLength(sb.length() - 1); + + return sb.toString(); } public int prefixLength(String pathname) {