[Bf-blender-cvs] [50d26e7c78c] blender2.8: Speedup: optimize DNA_elem_array_size to speedup file loading

Jacques Lucke noreply at git.blender.org
Thu Dec 6 15:52:33 CET 2018


Commit: 50d26e7c78cd1d226550d94ff761af5128f0ca8e
Author: Jacques Lucke
Date:   Thu Dec 6 15:50:01 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB50d26e7c78cd1d226550d94ff761af5128f0ca8e

Speedup: optimize DNA_elem_array_size to speedup file loading

Reviewers: brecht

Differential Revision: https://developer.blender.org/D4037

===================================================================

M	source/blender/makesdna/intern/dna_genfile.c

===================================================================

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 ********************** */



More information about the Bf-blender-cvs mailing list