Skip to content

Commit 6dcc73d

Browse files
Optimize Gem::Text#format_text performance and correct indentation
1 parent edf0012 commit 6dcc73d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib/rubygems/text.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def format_text(text, wrap, indent = 0)
2525
result = []
2626
work = clean_text(text)
2727

28-
while work.length > wrap do
28+
while work.length > wrap
2929
if work =~ /^(.{0,#{wrap}})[ \n]/
3030
result << $1.rstrip
31-
work.slice!(0, $&.length)
31+
work = work.slice($&.length..-1)
3232
else
33-
result << work.slice!(0, wrap)
33+
result << work.slice(0, wrap)
34+
work = work.slice(wrap..-1)
3435
end
3536
end
36-
3737
result << work if work.length.nonzero?
3838
result.join("\n").gsub(/^/, " " * indent)
3939
end

0 commit comments

Comments
 (0)