Speedup: optimize DNA_elem_array_size to speedup file loading
Reviewers: brecht Differential Revision: https://developer.blender.org/D4037
This commit is contained in:
parent
39efb58446
commit
50d26e7c78
|
@ -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 ********************** */
|
||||
|
|
Loading…
Reference in New Issue