From 7f400289b8ccc26f41e66cd6337a37bdaaec51e7 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 22 Jun 2011 20:55:54 +0200 Subject: [PATCH] Faster load of the content file. --- HISTORY | 2 +- TODO | 2 +- state.c | 2 +- util.c | 56 ++++++++++++++++++++++++++++++++------------------------ 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/HISTORY b/HISTORY index 1ebcb6a9..dd2b2e27 100644 --- a/HISTORY +++ b/HISTORY @@ -3,7 +3,7 @@ SnapRAID HISTORY 1.5 2011/6 ========== -* In the configuration file extra space are ignored. +* Ignores extra spaces in the configuration file. * Changed the output of check/fix to allow a more easily postprocessing with other tools like awk and sort. * Added the hidden option -G/--gui to enable the output of progress diff --git a/TODO b/TODO index 1b137214..73e28ec6 100644 --- a/TODO +++ b/TODO @@ -3,7 +3,7 @@ SnapRAID TODO This is a list of possible TODO items for SnapRAID. The order is not relevant. -* If a file cannot be synched, for example because it was changing, of it +* If a file cannot be synched, for example because it was changing, or it the file name cannot be supported, it's better to do not stop the sync process. The sync process should stop only if the error could be caused by a disk corruption. diff --git a/state.c b/state.c index 57fee0ae..cc4c16d2 100644 --- a/state.c +++ b/state.c @@ -311,7 +311,7 @@ void state_read(struct snapraid_state* state) tag = s; s = strtoken(s); - + if (strcmp(tag, "blk") == 0 || strcmp(tag, "inv") == 0) { char* pos; char* hash; diff --git a/util.c b/util.c index 72ca7270..87bd9000 100644 --- a/util.c +++ b/util.c @@ -125,40 +125,48 @@ void strenchex(char* str, const void* void_data, unsigned data_len) } } +static unsigned strdecset[256] = +{ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 +}; + char* strdechex(void* void_data, unsigned data_len, char* str) { unsigned char* data = void_data; unsigned i; for(i=0;i= '0' && c0 <= '9') - b0 = c0 - '0'; - else if (c0 >= 'a' && c0 <= 'f') - b0 = c0 - 'a' + 10; - else if (c0 >= 'A' && c0 <= 'F') - b0 = c0 - 'A' + 10; - else + b0 = strdecset[(unsigned char)str[0]]; + b1 = strdecset[(unsigned char)str[1]]; + + b = (b0 << 4) | b1; + + if (b > 0xFF) return str; - ++str; - c1 = *str; - if (c1 >= '0' && c1 <= '9') - b1 = c1 - '0'; - else if (c1 >= 'a' && c1 <= 'f') - b1 = c1 - 'a' + 10; - else if (c1 >= 'A' && c1 <= 'F') - b1 = c1 - 'A' + 10; - else - return str; - ++str; + data[0] = b; - data[i] = (b0 << 4) | b1; + data += 1; + str += 2; } return 0;