Closed Bug 393986 Opened 17 years ago Closed 17 years ago

Unnecessarily creating arrays using map in page info (should use forEach)

Categories

(Firefox :: Page Info Window, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED
Firefox 3 alpha8

People

(Reporter: Waldo, Assigned: florian)

References

()

Details

Attachments

(1 file)

I see a lot of |list.map(fun)| in Page Info; there's nothing wrong with this if you're using the return value of |map|, but everything here isn't, so an array of |undefined| items is being created for each of these, to hang around until garbage collection destroys it. There's no real harm, but if |forEach| were used instead of |map| the temporary wouldn't need to be created or GC'd.
Attached patch patch v1Splinter Review
Assignee: nobody → f.qu
Status: NEW → ASSIGNED
Attachment #278615 - Flags: review?(mano)
Comment on attachment 278615 [details] [diff] [review] patch v1 >Index: browser/base/content/pageinfo/pageInfo.js >=================================================================== >RCS file: /cvsroot/mozilla/browser/base/content/pageinfo/pageInfo.js,v >retrieving revision 1.7 >diff -U 8 -p -r1.7 pageInfo.js >--- browser/base/content/pageinfo/pageInfo.js 6 Aug 2007 16:13:05 -0000 1.7 >+++ browser/base/content/pageinfo/pageInfo.js 28 Aug 2007 16:32:48 -0000 >@@ -333,17 +333,17 @@ function loadPageInfo() > > // and then the hard stuff > makeTabs(gDocument, gWindow); > > initFeedTab(); > onLoadPermission(); > > /* Call registered overlay init functions */ >- onLoadRegistry.map(function(func) { func(); }); >+ onLoadRegistry.forEach(function(func) { func(); }); This could be simplified to .forEach(func) in all instances which don't take parameters. r=mano otherwise.
Attachment #278615 - Flags: review?(mano) → review+
(In reply to comment #2) > (From update of attachment 278615 [details] [diff] [review]) > > /* Call registered overlay init functions */ > >- onLoadRegistry.map(function(func) { func(); }); > >+ onLoadRegistry.forEach(function(func) { func(); }); > > This could be simplified to .forEach(func) in all instances which don't take > parameters. > How would this work? forEach expects a callback function that it can call for each element of the array. I've tried it just to be sure it doesn't magically work, and I get this error: Error: func is not defined Source File: chrome://browser/content/pageinfo/pageInfo.js Line: 301
he must have just misread it, seeing instead the common 'mistake'.
yeah, oops, sorry.
Keywords: checkin-needed
Checking in browser/base/content/pageinfo/pageInfo.js; /cvsroot/mozilla/browser/base/content/pageinfo/pageInfo.js,v <-- pageInfo.js new revision: 1.8; previous revision: 1.7 done
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Flags: in-testsuite-
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → Firefox 3 M8
Version: unspecified → Trunk
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: