summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2008-10-07 12:39:14 +0200
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2008-10-07 12:39:14 +0200
commit56fbdc2372f1afbe90bc0386ef714115884dbca3 (patch)
tree2e5a8753e76b92d8c9b5009486227e8c4b1ea443
parent46abfd7b12613aa565beaf163a0679f59e03480a (diff)
downloadpianobar-windows-56fbdc2372f1afbe90bc0386ef714115884dbca3.tar.gz
pianobar-windows-56fbdc2372f1afbe90bc0386ef714115884dbca3.tar.bz2
pianobar-windows-56fbdc2372f1afbe90bc0386ef714115884dbca3.zip
piano: Use faster hex2int conversion
-rw-r--r--libpiano/src/crypt.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/libpiano/src/crypt.c b/libpiano/src/crypt.c
index eef1057..43edd0c 100644
--- a/libpiano/src/crypt.c
+++ b/libpiano/src/crypt.c
@@ -38,15 +38,12 @@ THE SOFTWARE.
void PianoHexToInts (const char *strHex, unsigned int **retInts,
size_t *retIntsN) {
size_t i, strHexN = strlen (strHex);
- char hexInt[9];
unsigned int *arrInts = calloc (strHexN / 8, sizeof (*arrInts));
- /* FIXME: error handling: string too short, e.g. */
/* unsigned int = 4 bytes, 8 chars in hex */
- for (i = 0; i < strHexN; i += 8) {
- memcpy (hexInt, strHex+i, sizeof (hexInt)-1);
- hexInt[sizeof (hexInt) - 1] = 0;
- sscanf (hexInt, "%x", &arrInts[i/8]);
+ for (i = 0; i < strHexN; i++) {
+ arrInts[i/8] |= ((strHex[i] < 'a' ? strHex[i]: strHex[i] + 9) &
+ 0x0f) << (7*4 - i*4);
}
*retInts = arrInts;
*retIntsN = strHexN / 8;