Closed Bug 1575343 Opened 5 years ago Closed 5 years ago

Avoid extra copy when calling nsJSUtils::GetCallingLocation()'s nsACString overload

Categories

(Core :: DOM: Core & HTML, task)

task
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla70
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 ...

See Also: → 1574972

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.

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.

Pushed by amccreight@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/df88483c2aaf
part 1 - Avoid a gratuitous string copy by calling the nsAString overload of GetCallingLocation. r=smaug
https://hg.mozilla.org/integration/autoland/rev/71bcb9b6ae4a
part 2 - Avoid string copies when getting calling location in nsCSPContext. r=smaug
https://hg.mozilla.org/integration/autoland/rev/cdc9c1fc871e
part 3 - Avoid copies in workers and service workers when getting calling location. r=asuth
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla70
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: