avoided doing a strlen in align_string
let align_string return the new length
that way the caller can also avoid calling strlen

Signed-off-by: Frans Meulenbroeks <[email protected]>
---
 urjtag/src/svf/svf_flex.l |   31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/urjtag/src/svf/svf_flex.l b/urjtag/src/svf/svf_flex.l
index 37e996a..ad19763 100644
--- a/urjtag/src/svf/svf_flex.l
+++ b/urjtag/src/svf/svf_flex.l
@@ -49,7 +49,7 @@
 #define YY_EXTRA_TYPE urj_svf_scanner_extra_t *
 
 static int map_keyw_ident(YYSTYPE *, char *);
-static void align_string(char *);
+static int align_string(char *);
 
 static void fix_yylloc(YYLTYPE *, char *);
 static void fix_yylloc_nl(YYLTYPE *, char *, YY_EXTRA_TYPE);
@@ -143,11 +143,12 @@ COMMENT         (!.*)|("//".*)[^\n]
      This is enabled with <expect_vector>. */
   /* token is a vector string */
   char *cstring;
+  int len;
 
   fix_yylloc_nl(yylloc, yytext, yyget_extra(yyscanner));
-  align_string(yytext);
+  len = align_string(yytext);
 
-  cstring = malloc(strlen(yytext) + 1);
+  cstring = malloc(len + 1);
   strcpy(cstring, yytext);
   yylval->cvalue = cstring;
   return(VECTOR_STRING);
@@ -161,13 +162,16 @@ COMMENT         (!.*)|("//".*)[^\n]
      1024 is chosen arbitrarily, increasing to e.g. 4096 enhances scanner
      performance, trading off against huge table sizes.
      This whole strategy needs to be revisited with support of flex experts.
+     Actually svf files generated by Quartus II SVF converter 10.0 have 
+     fragments of 255 bytes as that is the data on a line
   */
   char *cstring;
+  int len;
 
   fix_yylloc_nl(yylloc, yytext, yyget_extra(yyscanner));
-  align_string(yytext);
+  len = align_string(yytext);
 
-  cstring = (char *)malloc(strlen(yytext) + 1);
+  cstring = (char *)malloc(len + 1);
   strcpy(cstring, yytext);
   yylval->cvalue = cstring;
   return(HEXA_NUM_FRAGMENT);
@@ -333,20 +337,19 @@ map_keyw_ident (YYSTYPE *mylval, char *str)
 }
 
 
-static void
+static int
 align_string (char *str)
 {
-    int src, dst, len;
-
-    dst = 0;
-    len = strlen (str);
+    char *src = str;
+    char *dst;
 
-    for (src = 0; src < len; src++)
+    for (dst = src; *src; src++)
     {
-        if (isxdigit (str[src]))
-            str[dst++] = str[src];
+        if (isxdigit (*src))
+           *dst++ = *src;
     }
-    str[dst] = '\0';
+    *dst = '\0';
+    return (dst - str);
 }
 
 
-- 
1.7.0.4


------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development

Reply via email to