Skip to content

A platform for community discussion. Free, open, simple.

PERF: Memoize PostRevisor#diff_size (#8939)

Dan Ungureanu82c84c51415f
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index fbd9c012bf2..03e6898a668 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -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