Skip to content

Commit

Permalink
reduced static variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jan 1, 2012
1 parent 8775ca8 commit fb91d3c
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pack.c
Expand Up @@ -1963,33 +1963,31 @@ pack_unpack(VALUE str, SEL sel, VALUE fmt)
char *ptr = (char *)rb_bstr_bytes(buf);
char *ptr_beg = ptr;
int a = -1,b = -1,c = 0,d;
static int first = 1;
static int b64_xtable[256];
static signed char b64_xtable[256];

if (first) {
if (b64_xtable['/'] <= 0) {
int i;
first = 0;

for (i = 0; i < 256; i++) {
b64_xtable[i] = -1;
}
for (i = 0; i < 64; i++) {
b64_xtable[(int)b64_table[i]] = i;
b64_xtable[(unsigned char)b64_table[i]] = i;
}
}
while (s < send) {
a = b = c = d = -1;
while((a = b64_xtable[(int)(*(unsigned char*)s)]) == -1 && s < send) { s++; }
if( s >= send ) break;
while ((a = b64_xtable[(unsigned char)*s]) == -1 && s < send) {s++;}
if (s >= send) break;
s++;
while((b = b64_xtable[(int)(*(unsigned char*)s)]) == -1 && s < send) { s++; }
if( s >= send ) break;
while ((b = b64_xtable[(unsigned char)*s]) == -1 && s < send) {s++;}
if (s >= send) break;
s++;
while((c = b64_xtable[(int)(*(unsigned char*)s)]) == -1 && s < send) { if( *s == '=' ) break; s++; }
if( *s == '=' || s >= send ) break;
while ((c = b64_xtable[(unsigned char)*s]) == -1 && s < send) {if (*s == '=') break; s++;}
if (*s == '=' || s >= send) break;
s++;
while((d = b64_xtable[(int)(*(unsigned char*)s)]) == -1 && s < send) { if( *s == '=' ) break; s++; }
if( *s == '=' || s >= send ) break;
while ((d = b64_xtable[(unsigned char)*s]) == -1 && s < send) {if (*s == '=') break; s++;}
if (*s == '=' || s >= send) break;
s++;
*ptr++ = a << 2 | b >> 4;
*ptr++ = b << 4 | c >> 2;
Expand Down

0 comments on commit fb91d3c

Please sign in to comment.