From 69b34c22eac140d63359bf503252f6fe5d89120f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 30 Aug 2010 20:07:29 +0000 Subject: [PATCH] src/svf/svf_flex.l (fix_yylloc): Accept the string length from caller to avoid useless overhead of calling strlen(). Fix by Frans Meulenbroeks. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1837 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 3 +++ urjtag/src/svf/svf_flex.l | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 904ea7f4..01b2ecff 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -8,6 +8,9 @@ the caller, and have the callers re-use that. This avoids useless overhead of calling strlen() over and over. Fix by Frans Meulenbroeks. + * src/svf/svf_flex.l (fix_yylloc): Accept the string length from caller to + avoid useless overhead of calling strlen(). 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 ad197633..bc0f2e20 100644 --- a/urjtag/src/svf/svf_flex.l +++ b/urjtag/src/svf/svf_flex.l @@ -51,7 +51,7 @@ static int map_keyw_ident(YYSTYPE *, char *); static int align_string(char *); -static void fix_yylloc(YYLTYPE *, char *); +static void fix_yylloc(YYLTYPE *, char *, int); static void fix_yylloc_nl(YYLTYPE *, char *, YY_EXTRA_TYPE); static void progress_nl(YYLTYPE *, YY_EXTRA_TYPE); @@ -87,7 +87,7 @@ COMMENT (!.*)|("//".*)[^\n] /* token is a keyword or identifier */ int keyw; - fix_yylloc(yylloc, yytext); + fix_yylloc(yylloc, yytext, yyleng); keyw = map_keyw_ident(yylval, yytext); /* enable detection of VECTOR_STRING when this is a PIO command */ @@ -125,7 +125,7 @@ COMMENT (!.*)|("//".*)[^\n] *point_pos = extra->decimal_point; yylval->dvalue = strtod(real_string, (char **) NULL); - fix_yylloc(yylloc, yytext); + fix_yylloc(yylloc, yytext, yyleng); free(real_string); } else @@ -180,18 +180,18 @@ COMMENT (!.*)|("//".*)[^\n] {WSPACE}+ { /* token is a white space character */ - fix_yylloc(yylloc, yytext); + fix_yylloc(yylloc, yytext, yyleng); } /* end of white space */ {COMMENT} { /* token is a comment */ - fix_yylloc(yylloc, yytext); + fix_yylloc(yylloc, yytext, yyleng); } /* end of comment */ "(" { - fix_yylloc(yylloc, yytext); + fix_yylloc(yylloc, yytext, yyleng); return(yytext[0]); } /* end of left or right parenthesis */ @@ -199,13 +199,13 @@ COMMENT (!.*)|("//".*)[^\n] /* scanning until a left parenthesis under this start condition implicitly skips whitespace that would have been attributed to HEXA_NUM_FRAGMENT otherwise */ - fix_yylloc(yylloc, yytext); + fix_yylloc(yylloc, yytext, yyleng); /* now hand over to HEXA_NUM_FRAGMENT */ BEGIN(expect_hexa_num); return(yytext[0]); } /* end of left or right parenthesis */ ")" { - fix_yylloc(yylloc, yytext); + fix_yylloc(yylloc, yytext, yyleng); BEGIN(INITIAL); return(yytext[0]); } /* end of left or right parenthesis */ @@ -227,7 +227,7 @@ COMMENT (!.*)|("//".*)[^\n] /* release start condition */ BEGIN(INITIAL); - fix_yylloc(yylloc, yytext); + fix_yylloc(yylloc, yytext, yyleng); return(yytext[0]); } /* end of statement character */ @@ -354,11 +354,11 @@ align_string (char *str) static void -fix_yylloc (YYLTYPE *mylloc, char *str) +fix_yylloc (YYLTYPE *mylloc, char *str, int len) { mylloc->first_line = mylloc->last_line; mylloc->first_column = mylloc->last_column; - mylloc->last_column += strlen (str); + mylloc->last_column += len; }