diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index ffd3e510..904ea7f4 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -4,6 +4,10 @@ whatever pkg-config tells us. Also allow libusb-1.0 + ftdi w/out async since it isn't required for things to work. + * src/svf/svf_flex.l: Have align_string return the length of the string to + the caller, and have the callers re-use that. This avoids useless overhead + of calling strlen() over and over. Fix by Frans Meulenbroeks. + 2010-08-26 Mike Frysinger * src/tap/cable/gpio.c: Rewrite to use raw file descriptors when working with diff --git a/urjtag/src/svf/svf_flex.l b/urjtag/src/svf/svf_flex.l index 37e996ae..ad197633 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 . */ /* 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); }