-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Reline::Unicode ed_ vi_ em_ methods #720
base: master
Are you sure you want to change the base?
Conversation
789d090
to
85f4405
Compare
lib/reline/unicode.rb
Outdated
end | ||
[byte_size, width, new_str] | ||
gcs = line.byteslice(byte_pointer..).grapheme_clusters | ||
nonwords = gcs.take_while { |c| c.encode(Encoding::UTF_8).match?(/\P{Word}/) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to encode gcs
all at once before looping through them?
Also, all tests still pass even if I removed these encoding calls. Can we add a few cases for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encode
will change bytesize, so I have to fix all encode(Encoding::UTF_8).grapheme_clusters
in this file to return the correct bytesize in original encoding. I'll also add a test.
2f519c3
to
3365ab0
Compare
3365ab0
to
e699b4f
Compare
e699b4f
to
2ad27a7
Compare
Depend on #759 (split some commits to it)
Refactor Reline::Unicode vi_ ed_ em_ methods
Rewrite them with about -250 lines.
Update questionable test case.
Description of refactor
Using get_prev_mbchar_size and get_next_mbchar_size in a
while
loop is extreamly inefficient.Using
take_while
to an array of grapheme_cluster is simple and fast enough.Performance
Scenario: paste 2KB text
aaaaa...aaaaa
to IRB and press OPTION+LEFT.