Closed Bug 1500927 Opened 2 years ago Closed 2 years ago
Add copy-free jsstring support to perfecthash
This is needed for bug 1500926, and could generally be advantageous for XPIDL as well, to avoid copies when looking up xpcom interfaces by name. The approach I took was to split the codegen logic out into a helper object. This object has separate methods for generating each piece, and has separate methods for generating a WebIDL lookup method and a bytes lookup method. If a component needs both the native string and JSString lookup methods, it will have 2 copies of the bases table. Fortunately these tables are usually fairly small for our code at the moment. If it proves to be an issue, we can perform a refactoring to avoid this restriction.
This is needed for bug 1500926. It takes the approach of taking a JSFlatString and using AutoAssertCannotGC to read the memory directly from the JS heap. This lets us avoid re-encoding strings when performing lookups, which can be advantageous. Only ASCII strings are supported by this handler, and wide strings are hashed as though they contain only values under 0x7f. This is OK as invalid keys to perfecthash may return any hashtable entry.
This is an example generated file from bug 1500926
Pushed by email@example.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/fbb568aa121e Add copy-free jsstring support to perfecthash.py, r=bzbarsky
You need to log in before you can comment on or make changes to this bug.