eBooru/app/logical/diffy_no_subprocess.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

16 lines
579 B
Ruby

# frozen_string_literal: true
# Diffy normally calls out to git diff, this makes it use libgit2 instead
module DiffyNoSubprocess
# https://github.com/samg/diffy/blob/85b18fa6b659f724937dea58ebbc0564f4475c8c/lib/diffy/diff.rb#L43-L77
def diff
@diff ||= Rugged::Patch.from_strings(@string1, @string2, context_lines: 10_000).to_s.force_encoding("UTF-8")
end
# https://github.com/samg/diffy/blob/85b18fa6b659f724937dea58ebbc0564f4475c8c/lib/diffy/diff.rb#L79-L100
def each(&)
# The first 5 lines are git diff header lines
diff.lines.drop(5).each(&)
end
end