projects
/
oweals
/
musl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
427173b
)
comment non-obvious de bruijn sequence code in int parser
author
Rich Felker
<dalias@aerifal.cx>
Mon, 25 Jul 2011 13:21:40 +0000
(09:21 -0400)
committer
Rich Felker
<dalias@aerifal.cx>
Mon, 25 Jul 2011 13:21:40 +0000
(09:21 -0400)
src/internal/intparse.c
patch
|
blob
|
history
diff --git
a/src/internal/intparse.c
b/src/internal/intparse.c
index fd403b589320633744d58fff0a17c3c7b366d9d4..90aa8339f1a35e48a0dfe55218aafa58a99746ad 100644
(file)
--- 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;