mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-05 09:00:07 +00:00
perf(gitdiff): optimize inline diff highlighting using cache (#38706)
This pull request optimizes code diff highlighting in the PR Files Changed view, which is a major CPU bottleneck and hot path in production. Previously, Gitea executed the expensive `DiffMatchPatch` algorithm twice for every matching deleted/added line pair (once for the deleted line, and once for the added line). We now run the diff algorithm once and cache the resulting `DiffInline` on the `DiffLine` struct itself, allowing the second line to render via a 0-cost cache lookup. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -10,14 +10,8 @@ type EscapeStatus struct {
|
||||
HasAmbiguous bool
|
||||
}
|
||||
|
||||
// Or combines two EscapeStatus structs into one representing the conjunction of the two
|
||||
func (status *EscapeStatus) Or(other *EscapeStatus) *EscapeStatus {
|
||||
st := status
|
||||
if status == nil {
|
||||
st = &EscapeStatus{}
|
||||
}
|
||||
func (st *EscapeStatus) Combine(other *EscapeStatus) {
|
||||
st.Escaped = st.Escaped || other.Escaped
|
||||
st.HasAmbiguous = st.HasAmbiguous || other.HasAmbiguous
|
||||
st.HasInvisible = st.HasInvisible || other.HasInvisible
|
||||
return st
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user