[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53407] trunk/blender/source/blender/ editors/space_text/text_format_py.c: code cleanup: text editor syntax highlighting - avoid loops using memset()

Campbell Barton ideasman42 at gmail.com
Sat Dec 29 17:18:06 CET 2012


Revision: 53407
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53407
Author:   campbellbarton
Date:     2012-12-29 16:18:03 +0000 (Sat, 29 Dec 2012)
Log Message:
-----------
code cleanup: text editor syntax highlighting - avoid loops using memset()

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_text/text_format_py.c

Modified: trunk/blender/source/blender/editors/space_text/text_format_py.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format_py.c	2012-12-29 16:04:45 UTC (rev 53406)
+++ trunk/blender/source/blender/editors/space_text/text_format_py.c	2012-12-29 16:18:03 UTC (rev 53407)
@@ -231,27 +231,28 @@
 				*fmt = 'l';
 			}
 			/* Whitespace (all ws. has been converted to spaces) */
-			else if (*str == ' ')
+			else if (*str == ' ') {
 				*fmt = '_';
+			}
 			/* Numbers (digits not part of an identifier and periods followed by digits) */
-			else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1))))
+			else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1)))) {
 				*fmt = 'n';
+			}
 			/* Booleans */
-			else if (prev != 'q' && (i = txtfmt_py_find_bool(str)) != -1)
+			else if (prev != 'q' && (i = txtfmt_py_find_bool(str)) != -1) {
 				if (i > 0) {
-					while (i > 1) {
-						*fmt = 'n'; fmt++; str++;
-						i--;
-					}
-					*fmt = 'n';
+					memset(fmt, 'n', i);
+					i--; fmt += i; str += i;
 				}
 				else {
 					str += BLI_str_utf8_size_safe(str) - 1;
 					*fmt = 'q';
 				}
+			}
 			/* Punctuation */
-			else if (text_check_delim(*str))
+			else if (text_check_delim(*str)) {
 				*fmt = '!';
+			}
 			/* Identifiers and other text (no previous ws. or delims. so text continues) */
 			else if (prev == 'q') {
 				str += BLI_str_utf8_size_safe(str) - 1;
@@ -260,18 +261,13 @@
 			/* Not ws, a digit, punct, or continuing text. Must be new, check for special words */
 			else {
 				/* Special vars(v) or built-in keywords(b) */
-				if ((i = txtfmt_py_find_specialvar(str)) != -1)
-					prev = 'v';
-				else if ((i = txtfmt_py_find_builtinfunc(str)) != -1)
-					prev = 'b';
-				else if ((i = txtfmt_py_find_decorator(str)) != -1)
-					prev = 'v';  /* could have a new color for this */
+				if      ((i = txtfmt_py_find_specialvar(str))   != -1) prev = 'v';
+				else if ((i = txtfmt_py_find_builtinfunc(str))  != -1) prev = 'b';
+				else if ((i = txtfmt_py_find_decorator(str))    != -1) prev = 'v';  /* could have a new color for this */
+
 				if (i > 0) {
-					while (i > 1) {
-						*fmt = prev; fmt++; str++;
-						i--;
-					}
-					*fmt = prev;
+					memset(fmt, prev, i);
+					i--; fmt += i; str += i;
 				}
 				else {
 					str += BLI_str_utf8_size_safe(str) - 1;




More information about the Bf-blender-cvs mailing list