summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-07-25 09:21:40 -0400
committerRich Felker <dalias@aerifal.cx>2011-07-25 09:21:40 -0400
commitdd92a09ecac74760823b047c074e4b21a8cb531f (patch)
treeea115f59b02f3a691107a2a7440016b5a3050abd
parent427173b9325d604d30650c16f1774942130aec52 (diff)
downloadmusl-dd92a09ecac74760823b047c074e4b21a8cb531f.tar.gz
musl-dd92a09ecac74760823b047c074e4b21a8cb531f.tar.bz2
musl-dd92a09ecac74760823b047c074e4b21a8cb531f.tar.xz
musl-dd92a09ecac74760823b047c074e4b21a8cb531f.zip
comment non-obvious de bruijn sequence code in int parser
-rw-r--r--src/internal/intparse.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/internal/intparse.c b/src/internal/intparse.c
index fd403b58..90aa8339 100644
--- a/src/internal/intparse.c
+++ b/src/internal/intparse.c
@@ -70,6 +70,8 @@ int __intparse(struct intparse *v, const void *buf, size_t n)
for (; n && *s-'0'<10U && v->small<=SLIM; n--, s++)
v->small = v->small * 10 + (*s-'0');
} else if ((b&-b) == b) {
+ /* Compute bitshift for power-of-two bases
+ * using a De Bruijn B(2,3) sequence. */
int bs = "\0\1\2\4\7\3\6\5"[(0x17*b)>>5&7];
for (; n && (d=digits[*s])<b && v->small<=SLIM; n--, s++)
v->small = (v->small<<bs) + d;