PERF: Memoize PostRevisor#diff_size (#8939)

Although this method is usually called twice, its execution can take
about 1s.
This commit is contained in:
Dan Ungureanu 2020-02-12 19:47:48 +02:00 committed by GitHub
parent 9c96511ec4
commit 82c84c5141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -287,8 +287,10 @@ class PostRevisor
end
def diff_size(before, after)
ONPDiff.new(before, after).short_diff.sum do |str, type|
type == :common ? 0 : str.size
@diff_size ||= begin
ONPDiff.new(before, after).short_diff.sum do |str, type|
type == :common ? 0 : str.size
end
end
end