Closed Bug 1180211 Opened 9 years ago Closed 9 years ago

Don't emit bytecode for empty strings in emitTemplateString

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla42
Tracking Status
firefox42 --- fixed

People

(Reporter: jandem, Assigned: jandem)

Details

Attachments

(1 file)

Attached patch PatchSplinter Review
When filing bug 1180184, I noticed that for a template string like `${1}${2}` we currently emit:

00000:  string ""
00005:  int8 2
00007:  tostring
00008:  add
00009:  string ""
00014:  add
00015:  int8 3
00017:  tostring
00018:  add
00019:  string ""
00024:  add
00025:  return

With the attached patch we skip the empty strings and emit just 1 JSOP_ADD instead of 4:

00000:  int8 2
00002:  tostring
00003:  int8 3
00005:  tostring
00006:  add
00007:  return

I think doing simple optimizations like this in the emitter is still worthwhile.
Attachment #8629371 - Flags: review?(jorendorff)
Does this do the right thing with tagged templates?  That is, given:

  foo`${1}${2`

  function foo() {
  }

is foo passed the same arguments after this patch as before?
(In reply to Boris Zbarsky [:bz] from comment #1)
> Does this do the right thing with tagged templates?

Yeah, bytecode for that is emitted somewhere else. It looks like this before and after the patch:

00005:  getgname "foo"
00010:  gimplicitthis "foo"
00015:  callsiteobj ["", "", ""]
00020:  one
00021:  int8 2
00023:  call 3
Attachment #8629371 - Flags: review?(jorendorff) → review+
https://hg.mozilla.org/mozilla-central/rev/02187d02a60a
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: