Ignore:
Timestamp:
2013-08-22T14:41:30+02:00 (13 years ago)
Author:
Don-vip
Message:

see #8902 - Small performance enhancements / coding style (patches by shinigami):

  • bytestohexstring.diff: byte[] to hex string change + small test
  • collfix.diff : problem in generic collection definition
  • styleiteration.diff: useless iteration to do end of list
  • environment.diff: Environment - merge chained ops (each created copy of env.) to one
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6123 r6175  
    401401    }
    402402
     403    private static final char[] HEX_ARRAY = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
     404
    403405    /**
    404406     * Converts a byte array to a string of hexadecimal characters.
     
    409411     */
    410412    public static String toHexString(byte[] bytes) {
    411         char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
    412         char[] hexChars = new char[bytes.length * 2];
    413         for (int j=0; j<bytes.length; j++) {
    414             int v = bytes[j] & 0xFF;
    415             hexChars[j*2] = hexArray[v/16];
    416             hexChars[j*2 + 1] = hexArray[v%16];
     413
     414        if (bytes == null) {
     415            return "";
     416        }
     417
     418        final int len = bytes.length;
     419        if (len == 0) {
     420            return "";
     421        }
     422
     423        char[] hexChars = new char[len * 2];
     424        for (int i = 0, j = 0; i < len; i++) {
     425            final int v = bytes[i];
     426            hexChars[j++] = HEX_ARRAY[(v & 0xf0) >> 4];
     427            hexChars[j++] = HEX_ARRAY[v & 0xf];
    417428        }
    418429        return new String(hexChars);
Note: See TracChangeset for help on using the changeset viewer.