Skip to content

Commit

Permalink
Run processors on whole of text (go-gitea#16155)
Browse files Browse the repository at this point in the history
There is an inefficiency in the design of our processors which means that Emoji
and other processors run in order n^2 time.

This PR forces the processors to process the entirety of text node before passing
back up. The fundamental inefficiency remains but it should be significantly
ameliorated.

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath authored and AbdulrhmnGhanem committed Aug 10, 2021
1 parent bd73877 commit 013540b
Show file tree
Hide file tree
Showing 3 changed files with 416 additions and 318 deletions.
5 changes: 5 additions & 0 deletions modules/emoji/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package emoji

import (
"io"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -145,6 +146,8 @@ func (n *rememberSecondWriteWriter) Write(p []byte) (int, error) {
if n.writecount == 2 {
n.idx = n.pos
n.end = n.pos + len(p)
n.pos += len(p)
return len(p), io.EOF
}
n.pos += len(p)
return len(p), nil
Expand All @@ -155,6 +158,8 @@ func (n *rememberSecondWriteWriter) WriteString(s string) (int, error) {
if n.writecount == 2 {
n.idx = n.pos
n.end = n.pos + len(s)
n.pos += len(s)
return len(s), io.EOF
}
n.pos += len(s)
return len(s), nil
Expand Down
Loading

0 comments on commit 013540b

Please sign in to comment.