forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize matching multiple literal characters
Summary: Hermes is a bytecode compiler for JavaScript. This diff will optimize the implementation of literal opcodes in its regex engine. Literal characters in a regex like /abcdefg/ are compiled as a sequence of MatchChar8 opcodes. This requires a separate instruction dispatch for each character. This diff will add a multi-character variant: a single regex opcode which can match multiple characters. Example: > echo '/abcd/' | hermes -dump-bytecode Header: marked: 0 loops: 0 flags: 0 constraints: 4 0000 MatchChar8: 'a' 0002 MatchChar8: 'b' 0004 MatchChar8: 'c' 0006 MatchChar8: 'd' 0008 Goal Should Be: Example: > echo '/abcd/' | hermes -dump-bytecode Header: marked: 0 loops: 0 flags: 0 constraints: 4 0000 MatchNChar8: 'abcd' 0006 Goal While this may not be a large 'win' in terms of instruction compression, it does make bytecode easier to read. The optimization only saves one byte per MatchChar, starting with the 3rd char in a group. Single chars should *not* become MatchNChar8 as doing so is less memory efficient, and less readible. Reviewed By: ridiculousfish Differential Revision: D16119452 fbshipit-source-id: 8f386a582d6d6a921f6c3bbf66280c05e682a4e8
- Loading branch information
1 parent
7e803f4
commit 8733459
Showing
6 changed files
with
301 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.