[Bf-committers] Some doubtful string code in resources.c

Alexander Ewering blender at instinctive.de
Thu Dec 2 22:06:55 CET 2004


I stumbled upon this piece of code while adding a few theme colors...

---SNIP---

 	if(spacetype==0) {
 		sprintf(str, "Outline %%x%d|", TH_BUT_OUTLINE); strcat(cp, str);
 		sprintf(str, "Neutral %%x%d|", TH_BUT_NEUTRAL); strcat(cp, str);
 		sprintf(str, "Action %%x%d|", TH_BUT_ACTION); strcat(cp, str);
 		sprintf(str, "Setting %%x%d|", TH_BUT_SETTING); strcat(cp, str);
 		sprintf(str, "Special Setting 1%%x%d|", TH_BUT_SETTING1); strcat(cp, str);
 		sprintf(str, "Special Setting 2 %%x%d|", TH_BUT_SETTING2); strcat(cp, str);
 		sprintf(str, "Number Input %%x%d|", TH_BUT_NUM); strcat(cp, str);
 		sprintf(str, "Text Input %%x%d|", TH_BUT_TEXTFIELD); strcat(cp, str);
 		sprintf(str, "Popup %%x%d|", TH_BUT_POPUP); strcat(cp, str);
 		sprintf(str, "Text %%x%d|", TH_BUT_TEXT); strcat(cp, str);
 		sprintf(str, "Text Highlight %%x%d|", TH_BUT_TEXT_HI); strcat(cp, str);
 			strcat(cp,"%l|");
 		sprintf(str, "Menu Background %%x%d|", TH_MENU_BACK); strcat(cp, str);
 		sprintf(str, "Menu Item %%x%d|", TH_MENU_ITEM); strcat(cp, str);
 		sprintf(str, "Menu Item Highlight %%x%d|", TH_MENU_HILITE); strcat(cp, str);
 		sprintf(str, "Menu Text %%x%d|", TH_MENU_TEXT); strcat(cp, str);
 		sprintf(str, "Menu Text Highlight %%x%d|", TH_MENU_TEXT_HI); strcat(cp, str);
 		strcat(cp,"%l|");
 		sprintf(str, "Drawtype %%x%d|", TH_BUT_DRAWTYPE); strcat(cp, str);
 	}

---SNAP---

I would like to point out that this is awfully slow (it has to count the
length of the string for EACH string added, and then copy str around).

Each of these lines can be simply replaced with:

cp+= sprintf(cp, "...", ...);

Sorry, I had to play "Code wiping woman" once in my life, too ;)

| alexander ewering              instinctive mediaworks
| ae[@]instinctive[.]de   http://www[.]instinctive[.]de


More information about the Bf-committers mailing list