Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/DigestHelper.java @ 266:0a2f445de774
Improve manifest parsing: reduce number of arrays instantiated for Nodeid
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 19 Aug 2011 04:59:32 +0200 |
parents | a3a2e5deb320 |
children | 981f9f50bb6c |
comparison
equal
deleted
inserted
replaced
265:3dd953c65619 | 266:0a2f445de774 |
---|---|
120 result[j++] = hexDigits.charAt((data[i] >>> 4) & 0x0F); | 120 result[j++] = hexDigits.charAt((data[i] >>> 4) & 0x0F); |
121 result[j++] = hexDigits.charAt(data[i] & 0x0F); | 121 result[j++] = hexDigits.charAt(data[i] & 0x0F); |
122 } | 122 } |
123 return new String(result); | 123 return new String(result); |
124 } | 124 } |
125 | |
126 public static boolean ascii2bin(byte[] ascii, int offset, int len, byte[] binary) { | |
127 assert len % 2 == 0; | |
128 assert binary.length >= len >>> 1; | |
129 | |
130 boolean zeroBytes = true; | |
131 for (int i = 0, j = offset; i < len >>> 1; i++) { | |
132 int b = ascii[j++] & 0xCF; // -0x30 to get decimal digit out from their char, and to uppercase if a letter | |
133 int hiNibble = b > 64 ? b - 55 : b; | |
134 b = ascii[j++] & 0xCF; | |
135 int lowNibble = b > 64 ? b - 55 : b; | |
136 if (hiNibble >= 16 || lowNibble >= 16) { | |
137 throw new IllegalArgumentException(String.format("Characters '%c%c' (%1$d and %2$d) at index %d are not valid hex digits", ascii[j-2], ascii[j-1], j-2)); | |
138 } | |
139 b = (((hiNibble << 4) | lowNibble) & 0xFF); | |
140 binary[i] = (byte) b; | |
141 zeroBytes = zeroBytes && b == 0; | |
142 } | |
143 return zeroBytes; | |
144 } | |
125 } | 145 } |