Skip to content
Snippets Groups Projects
Commit ea9c10f2 authored by rswindell's avatar rswindell
Browse files

Optimization: only calculate line length (using strlen) once per line.

parent 46f25cec
Branches
Tags
No related merge requests found
......@@ -492,6 +492,7 @@ long js_exec(const char *fname, char** args)
uint line_no;
char path[MAX_PATH+1];
char line[1024];
size_t len;
char* js_buf=NULL;
size_t js_buflen;
JSObject* js_scope=NULL;
......@@ -561,13 +562,14 @@ long js_exec(const char *fname, char** args)
if(line_no==1 && strncmp(line,"#!",2)==0)
strcpy(line,"\n"); /* To keep line count correct */
#endif
if((js_buf=realloc(js_buf,js_buflen+strlen(line)))==NULL) {
len=strlen(line);
if((js_buf=realloc(js_buf,js_buflen+len))==NULL) {
fprintf(errfp,"!Error allocating %u bytes of memory\n"
,js_buflen+strlen(line));
,js_buflen+len);
return(-1);
}
memcpy(js_buf+js_buflen,line,strlen(line));
js_buflen+=strlen(line);
memcpy(js_buf+js_buflen,line,len);
js_buflen+=len;
}
if((js_script=JS_CompileScript(js_cx, js_scope, js_buf, js_buflen, fname==NULL ? NULL : path, 1))==NULL) {
fprintf(errfp,"!Error compiling script from %s\n",path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment