Avoid extra copy when calling nsJSUtils::GetCallingLocation()'s nsACString overload
Categories
(Core :: DOM: Core & HTML, task)
Tracking
()
Tracking | Status | |
---|---|---|
firefox70 | --- | fixed |
People
(Reporter: mccr8, Assigned: mccr8)
References
Details
Attachments
(3 files)
It looks like a number of callers of nsJSUtils::GetCallingLocation()'s nsACString overload do this:
nsAutoCString spec;
nsJSUtils::GetCallingLocation(cx, spec, ...);
... NS_ConvertUTF8toUTF16(spec) ...
This copies the file name into the Cstring, then makes another copy to turn it into a cstring. If I'm reading the code correctly, this could be changed to this to avoid that intermediate copy:
nsAutoString spec;
nsJSUtils::GetCallingLocation(cx, spec, ...);
... spec ...
Assignee | ||
Comment 1•5 years ago
|
||
The nsAString overload of GetCallingLocation directly converts the
original source file name string into an nsAString. A number of
callers that want the source file name in an nsAString are calling the
nsACString overload of GetCallingLocation, then calling
NS_ConvertUTF8toUTF16. This results in an extra intermediate copy of
the original string data.
Assignee | ||
Comment 2•5 years ago
|
||
This code grabs the URI, then tries to overwrite it with information
from GetCallingLocation, then possibly overwrites it again with the
original information, then converts the string.
My patch reorders things so that we try GetCallingLocation() first, so
we only set the values once. In the case where GetCallingLocation()
succeeds it avoids a string copy from 8 to 16 bit.
Assignee | ||
Comment 3•5 years ago
|
||
Comment 5•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/df88483c2aaf
https://hg.mozilla.org/mozilla-central/rev/71bcb9b6ae4a
https://hg.mozilla.org/mozilla-central/rev/cdc9c1fc871e
Description
•