Closed Bug 212468 Opened 22 years ago Closed 22 years ago

rethink the hashtable usage in helperappservice

Categories

(Core Graveyard :: File Handling, defect, P1)

defect

Tracking

(Not tracked)

RESOLVED FIXED
mozilla1.5beta

People

(Reporter: Biesinger, Assigned: Biesinger)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Currently, the only entries that ever end up in the hashtable are those from defaultMimeEntries. which means that the table is rather useless, except to speed up mime type lookups by extension. so I would suggest removing that hashtable, removing rarely used entries from defaultMimeEntries, and in GetMimeTypeFromExtension just doing a linear search in defaultMimeEntries. The entries in there could be in the order xul,xml,rdf,gif,jpg,css,htm,html
If you're going to remove the ability to add new entries, why not just make a gperf table out of the existing defaultMimeEntries?
well... even today, that hashtable is not being added to... I'll consider that, but wouldn't that add a compile-time dependency on gperf?
I think alecf or shaver might know how to insert gperfed code into the build so that it can be built on machines without gperf. Using gperf at all here is just a suggestion. Although I think lookup will beat a linear search here, it may be over-optimization depending on how frequently this is called.
It's called somewhat frequently at startup (like for every .xul, .css, .gif, .rdf, .xml, etc in the chrome). But would a lookup really beat a linear search over 5-10 entries that we can order in order of frequency?
Depends on how biased the frequencies are. The tradeoff is around when the expected number of lookups for linear search crosses two (assuming the perfect hash code generator is good). If the number of types really can be cut to five, then simplicity wins. The difference between the two in that case should be microseconds.
Status: NEW → ASSIGNED
Comment on attachment 127752 [details] [diff] [review] patch Here's the count of the extensions used at startup on my system (Win32, Classic) GIF: 29 XML: 24 RDF: 10 XUL: 3
Attachment #127752 - Flags: review?(bzbarsky)
Priority: -- → P1
Target Milestone: --- → mozilla1.5beta
Comment on attachment 127752 [details] [diff] [review] patch >+ { TEXT_PLAIN, "txt,text", "Text File", 'TEXT', 'ttxt' }, >+#ifdef MOZ_SVG >+ { "image/svg+xml", "svg", "Scalable Vector Graphics", 'svg ', 'ttxt' }, >+#endif ..... Hey, as long as you're changing the order of these, please put them in a logical order? Eg, JPEG and GIF should be somewhere near PNG.... Also, I see no reason to have that #ifdef there now that this is not in the "no override possible" list. Finally, please put >+ { APPLICATION_XPINSTALL, "xpi", "XPInstall Install", 'xpi*','MOSS' }, in the "no override possible" list too, just in case. r=me with these changes.
Attachment #127752 - Flags: review?(bzbarsky) → review+
Comment on attachment 127752 [details] [diff] [review] patch bz: ok, I'll make those changes
Attachment #127752 - Flags: superreview?(darin)
Comment on attachment 127752 [details] [diff] [review] patch lot's of code removal... very nice. sr=darin
Attachment #127752 - Flags: superreview?(darin) → superreview+
requested changes made. I made the order mostly alphabetical. Checking in nsExternalHelperAppService.cpp; /cvsroot/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp,v <-- nsE xternalHelperAppService.cpp new revision: 1.201; previous revision: 1.200 done Checking in nsExternalHelperAppService.h; /cvsroot/mozilla/uriloader/exthandler/nsExternalHelperAppService.h,v <-- nsExt ernalHelperAppService.h new revision: 1.46; previous revision: 1.45 done
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
oh right, to address the gperf question: I ended up getting 4 types that had to be fast, so I used a normal array. (there are ~8 entries in that array, but for the last 4, speed doesn't matter so much)
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: