commit e37b96e759baad6d069a85c0a33ee90236c583e6
parent f8229ce1cbe19e494d3936c5f836b17e0478a1fa
Author: Vickenty Fesunov <kent@setattr.net>
Date: Wed, 24 Jun 2015 20:39:33 +0200
Make String.wrap faster.
Call slice_by_display_length() only once and keep the result.
Diffstat:
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -344,13 +344,14 @@ class String
ret = []
s = self
while s.display_length > len
- cut = s.slice_by_display_length(len).rindex(/\s/)
+ slice = s.slice_by_display_length(len)
+ cut = slice.rindex(/\s/)
if cut
ret << s[0 ... cut]
s = s[(cut + 1) .. -1]
else
- ret << s.slice_by_display_length(len)
- s = s[ret.last.length .. -1]
+ ret << slice
+ s = s[slice.length .. -1]
end
end
ret << s