Avoid js_strlen() call in js_NewStringCopyZ()

VERIFIED FIXED in mozilla0.9.4

Status

()

Core
JavaScript Engine
P3
trivial
VERIFIED FIXED
17 years ago
16 years ago

People

(Reporter: Bernard Alleysson, Assigned: brendan)

Tracking

({js1.5, perf})

Trunk
mozilla0.9.4
x86
Windows 2000
js1.5, perf
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

17 years ago
from jsstr.c rev 3.48

2298 JSString *
2299 js_NewStringCopyZ(JSContext *cx, const jschar *s, uintN gcflag)
2300 {
2301 size_t n, m;
2302 jschar *news;
2303 JSString *str;
2304 
2305 n = js_strlen(s);
2306 m = (n + 1) * sizeof(jschar);
2307 news = (jschar *) JS_malloc(cx, m);
2308 if (!news)
2309 return NULL;
2310 memcpy(news, s, m);
2311 str = js_NewString(cx, news, js_strlen(news), gcflag);
2312 if (!str)
2313 JS_free(cx, news);
2314 return str;
2315 }

it seems that js_strlen(news) == js_strlen(s) == n since news is a copy of s

so the patch would be to replace 
2311 str = js_NewString(cx, news, js_strlen(news), gcflag);
by
2311 str = js_NewString(cx, news, n, gcflag);

this will save a call to js_strlen

I know this is very little time but why waste cycles for that ?

Updated

17 years ago
Keywords: perf

Comment 1

17 years ago
cc'ing Brendan on this one -
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Assignee)

Comment 2

17 years ago
Dunno how that happened -- thanks for pointing it out.

/be
Assignee: rogerl → brendan
Keywords: js1.5, mozilla0.9.4
Priority: -- → P3
Target Milestone: --- → mozilla0.9.4
r=shaver on the patch proposed by Bernard.
(Assignee)

Comment 4

17 years ago
sr=brendan@mozilla.org, and I checked in bernard's patch -- thanks!

/be
Status: NEW → RESOLVED
Last Resolved: 17 years ago
Resolution: --- → FIXED

Comment 5

17 years ago
Verified -
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.