Closed Bug 1294616 Opened 8 years ago Closed 8 years ago

Somewhat improve the string performance over bug 1288320

Categories

(Core :: Audio/Video: Playback, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla51
Tracking Status
firefox51 --- fixed

People

(Reporter: jwwang, Assigned: jwwang)

References

Details

Attachments

(1 file)

By defining
static constexpr auto& str = "hello";
instead of
static const char* const str = "hello";

The length is known at compile time and we can call EqualsLiteral() instead of EqualsASCII() to slightly improve the performance.
Assignee: nobody → jwwang
Depends on: 1288320
Priority: -- → P3
Attachment #8780964 - Flags: review?(cpearce)
Comment on attachment 8780964 [details]
Bug 1294616 - Somewhat improve the string performance by defining string literals whose length is known at compile time.

https://reviewboard.mozilla.org/r/71472/#review71568

::: dom/media/eme/EMEUtils.cpp:138
(Diff revision 2)
>  }
>  
>  nsString
>  KeySystemToGMPName(const nsAString& aKeySystem)
>  {
> -  if (aKeySystem.EqualsASCII(kEMEKeySystemPrimetime)) {
> +  if (aKeySystem.EqualsASCII(kEMEKeySystemPrimetime.get(),

I'm not super keen on having to manually pass the length and raw char pointer to this. Can you use CompareUTF8toUTF16() instead? That does a length check too.
Attachment #8780964 - Flags: review?(cpearce) → review+
Sure. Thanks for the review!
Though, I would have thought you could use nsAString::EqualsLiteral(const char*) instead to get what you wanted?
nsAString::EqualsLiteral is less efficient for it doesn't have the length.
We have 3 strings to compare:
org.w3.clearkey
com.widevine.alpha
com.adobe.primetime

with different lengths.

So the compare functions can run in constant time when length is given.
Pushed by jwwang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/3d01226b50ef
Somewhat improve the string performance by defining string literals whose length is known at compile time. r=cpearce
https://hg.mozilla.org/mozilla-central/rev/3d01226b50ef
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla51
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: