[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41357] trunk/blender/source/blender: replace BLI_strtok_r from r41337 with lighter method that doesnt alloc for template_list

Campbell Barton ideasman42 at gmail.com
Sat Oct 29 10:18:44 CEST 2011


Revision: 41357
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41357
Author:   campbellbarton
Date:     2011-10-29 08:18:42 +0000 (Sat, 29 Oct 2011)
Log Message:
-----------
replace BLI_strtok_r from r41337 with lighter method that doesnt alloc for template_list

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41337

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_string.h
    trunk/blender/source/blender/blenlib/intern/bpath.c
    trunk/blender/source/blender/blenlib/intern/string.c
    trunk/blender/source/blender/editors/interface/interface_templates.c

Modified: trunk/blender/source/blender/blenlib/BLI_string.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_string.h	2011-10-29 07:14:31 UTC (rev 41356)
+++ trunk/blender/source/blender/blenlib/BLI_string.h	2011-10-29 08:18:42 UTC (rev 41357)
@@ -132,29 +132,6 @@
 int BLI_strncasecmp(const char *s1, const char *s2, size_t len);
 int BLI_natstrcmp(const char *s1, const char *s2);
 size_t BLI_strnlen(const char *str, size_t maxlen);
-
-	/**
-	 * Split str on the first occurence of delimiter, returns the first
-	 * part as a mallocN'd string, and stores the second part into
-	 * ctx (also mallocN'd).
-	 * If str is NULL, split on ctx instead.
-	 * This allows to iterate over this "generator" function:
-	 *
-	 * char *ctx = NULL;
-	 * char *res = NULL;
-	 * for(res = BLI_strtok_r("a;dummy;csv;line", ";", &ctx); res; res = BLI_strtok_r(NULL, ";", &ctx)) {
-	 *     printf(res);
-	 *     MEM_freeN(res);
-	 * }
-	 * 
-	 * @param str The string to be split.
-	 * @param delimiter The char used to split str apart.
-	 * @param ctx The "context" string. It’s a pointer inside the org passed @str,
-	 *            so it has no specific mem management.
-	 * @retval Returns the mallocN'd first element from split str (or ctx).
-	 */
-char *BLI_strtok_r(char *str, const char *delimiter, char **ctx);
-
 void BLI_timestr(double _time, char *str); /* time var is global */
 
 void BLI_ascii_strtolower(char *str, int len);

Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c	2011-10-29 07:14:31 UTC (rev 41356)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c	2011-10-29 08:18:42 UTC (rev 41357)
@@ -325,8 +325,7 @@
 	}
 
 	if (visit_cb(userdata, path_dst, (const char *)path_src)) {
-		BLI_split_dirfile(path_dst, path_dir, path_file,
-		                  sizeof(path_dir), sizeof(path_file));
+		BLI_split_dirfile(path_dst, path_dir, path_file, FILE_MAXDIR, FILE_MAXFILE);
 		return TRUE;
 	}
 	else {

Modified: trunk/blender/source/blender/blenlib/intern/string.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string.c	2011-10-29 07:14:31 UTC (rev 41356)
+++ trunk/blender/source/blender/blenlib/intern/string.c	2011-10-29 08:18:42 UTC (rev 41357)
@@ -375,35 +375,6 @@
 	return 0;
 }
 
-/* As unfortunately strtok_r is not available everywhere... */
-char *BLI_strtok_r(char *str, const char *delimiter, char **ctx)
-{
-	char *cut = NULL, *ret = NULL;
-	char *split = str ? str : *ctx;
-
-	if(!split) {
-		return ret;
-	}
-
-	cut = strchr(split, *delimiter);
-	if(cut) {
-		size_t len_ret = cut - split;
-		size_t len_ctx = strlen(split) - len_ret - 1;
-		ret = BLI_strdupn(split, len_ret);
-		if(len_ctx > 0) {
-			*ctx = split+len_ret+1;
-		}
-		else {
-			*ctx = NULL;
-		}
-	}
-	else {
-		ret = BLI_strdup(split);
-		*ctx = NULL;
-	}
-	return ret;
-}
-
 void BLI_timestr(double _time, char *str)
 {
 	/* format 00:00:00.00 (hr:min:sec) string has to be 12 long */

Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c	2011-10-29 07:14:31 UTC (rev 41356)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c	2011-10-29 08:18:42 UTC (rev 41357)
@@ -2059,7 +2059,7 @@
 	return rnaicon;
 }
 
-static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop, const char *prop_list)
+static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop, const char *prop_list_id)
 {
 	uiBlock *block= uiLayoutGetBlock(layout);
 	uiBut *but;
@@ -2184,8 +2184,7 @@
 	 * … you’ll get a numfield for the integer prop, a check box for the bool prop, and a textfield
 	 * for the string prop, after the name of each item of the collection.
 	 */
-	else if (prop_list) {
-		PropertyRNA *prop_ctrls;
+	else if (prop_list_id) {
 		row = uiLayoutRow(sub, 1);
 		uiItemL(row, name, icon);
 
@@ -2194,18 +2193,21 @@
 		 *      which would obviously produce a sigsev… */
 		if (itemptr->type) {
 			/* If the special property is set for the item, and it is a collection… */
-			prop_ctrls = RNA_struct_find_property(itemptr, prop_list);
-			if(prop_ctrls) {
-				if(RNA_property_type(prop_ctrls) == PROP_STRING) {
-					char *prop_names = RNA_property_string_get_alloc(itemptr, prop_ctrls, NULL, 0, NULL);
-					char *id = NULL;
-					char *ctx = NULL;
-					for(id = BLI_strtok_r(prop_names, ":", &ctx); id; id = BLI_strtok_r(NULL, ":", &ctx)) {
-						uiItemR(row, itemptr, id, 0, NULL, 0);
-						MEM_freeN(id);
-					}
-					MEM_freeN(prop_names);
+			PropertyRNA *prop_list= RNA_struct_find_property(itemptr, prop_list_id);
+
+			if(prop_list && RNA_property_type(prop_list) == PROP_STRING) {
+				int prop_names_len;
+				char *prop_names = RNA_property_string_get_alloc(itemptr, prop_list, NULL, 0, &prop_names_len);
+				char *prop_names_end= prop_names + prop_names_len;
+				char *id= prop_names;
+				char *id_next;
+				while (id < prop_names_end) {
+					if ((id_next= strchr(id, ':'))) *id_next++= '\0';
+					else id_next= prop_names_end;
+					uiItemR(row, itemptr, id, 0, NULL, 0);
+					id= id_next;
 				}
+				MEM_freeN(prop_names);
 			}
 		}
 	}




More information about the Bf-blender-cvs mailing list