diff options
author | Sv. Lockal <lockalsash@gmail.com> | 2013-12-15 18:06:04 +0400 |
---|---|---|
committer | Sv. Lockal <lockalsash@gmail.com> | 2013-12-15 18:06:04 +0400 |
commit | 2b0ba65c513b362617556551028360184f58ecc1 (patch) | |
tree | f24db0f5ab6b3b5a541cf6fab34d75363cae886f /source/blender/makesdna/intern/makesdna.c | |
parent | 4a141022c39cefd422e66772714f54ccb3ec7733 (diff) |
Minor optimization for strlen and memcpy calls for reading blend files
Summary:
This commit removes ~10000 strlen calls and ~100000 memcpy calls in blender (profiled with blender --background), ~10000 memcpy calls in makesdna.
There is no need to create null-terminated strings for atoi, because it converts only the initial portion of the string anyway.
Also it was noticed that DNA_elem_array_size and arraysize functions work only with full strings, so there is no point to calculate strlen.
Reviewers: campbellbarton
Reviewed By: campbellbarton
Differential Revision: http://developer.blender.org/D105
Diffstat (limited to 'source/blender/makesdna/intern/makesdna.c')
-rw-r--r-- | source/blender/makesdna/intern/makesdna.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index aac79245501..39bf5ec437f 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -201,7 +201,7 @@ static int convert_include(char *filename); /** * Determine how many bytes are needed for an array. */ -static int arraysize(char *astr, int len); +static int arraysize(const char *str); /** * Determine how many bytes are needed for each struct. @@ -699,19 +699,16 @@ static int convert_include(char *filename) return 0; } -static int arraysize(char *astr, int len) +static int arraysize(const char *str) { int a, mul = 1; - char str[100], *cp = NULL; - - memcpy(str, astr, len + 1); + const char *cp = NULL; - for (a = 0; a < len; a++) { + for (a = 0; str[a]; a++) { if (str[a] == '[') { cp = &(str[a + 1]); } else if (str[a] == ']' && cp) { - str[a] = 0; /* if 'cp' is a preprocessor definition, it will evaluate to 0, * the caller needs to check for this case and throw an error */ mul *= atoi(cp); @@ -725,7 +722,7 @@ static int calculate_structlens(int firststruct) { int a, b, len_native, len_64, unknown = nr_structs, lastunknown, structtype, type, mul, namelen; short *sp, *structpoin; - char *cp; + const char *cp; int has_pointer, dna_error = 0; while (unknown) { @@ -756,7 +753,7 @@ static int calculate_structlens(int firststruct) has_pointer = 1; /* has the name an extra length? (array) */ mul = 1; - if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen); + if (cp[namelen - 1] == ']') mul = arraysize(cp); if (mul == 0) { printf("Zero array size found or could not parse %s: '%.*s'\n", types[structtype], namelen + 1, cp); @@ -794,7 +791,7 @@ static int calculate_structlens(int firststruct) else if (typelens_native[type]) { /* has the name an extra length? (array) */ mul = 1; - if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen); + if (cp[namelen - 1] == ']') mul = arraysize(cp); if (mul == 0) { printf("Zero array size found or could not parse %s: '%.*s'\n", types[structtype], namelen + 1, cp); |