diff options
author | Jacques Lucke <mail@jlucke.com> | 2018-12-06 17:50:01 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2018-12-06 17:50:01 +0300 |
commit | 50d26e7c78cd1d226550d94ff761af5128f0ca8e (patch) | |
tree | 596e975beed69a8e4214370471522c1c061e95e7 | |
parent | 39efb58446eb7af0f3ab10f8316ba81f465cdc17 (diff) |
Speedup: optimize DNA_elem_array_size to speedup file loading
Reviewers: brecht
Differential Revision: https://developer.blender.org/D4037
-rw-r--r-- | source/blender/makesdna/intern/dna_genfile.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index 2881f3138b2..ef9c27be196 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -139,23 +139,39 @@ /* allowed duplicate code from makesdna.c */ /** - * parses the "[n]" on the end of an array name and returns the number of array elements n. + * parses the "[n1][n2]..." on the end of an array name and returns the number of array elements n1*n2*... */ int DNA_elem_array_size(const char *str) { - int a, mul = 1; - const char *cp = NULL; - - for (a = 0; str[a]; a++) { - if (str[a] == '[') { - cp = &(str[a + 1]); - } - else if (str[a] == ']' && cp) { - mul *= atoi(cp); + int result = 1; + int current = 0; + while (true) { + char c = *str++; + switch (c) { + case '\0': + return result; + case '[': + current = 0; + break; + case ']': + result *= current; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + current = current * 10 + (c - '0'); + break; + default: + break; } } - - return mul; } /* ************************* END MAKE DNA ********************** */ |