Skip to content

Commit 0db1048

Browse files
authored
Run processors on whole of text (#16155)
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 <[email protected]>
1 parent 6ad5d0a commit 0db1048

File tree

3 files changed

+416
-318
lines changed

3 files changed

+416
-318
lines changed

modules/emoji/emoji.go

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package emoji
77

88
import (
9+
"io"
910
"sort"
1011
"strings"
1112
"sync"
@@ -145,6 +146,8 @@ func (n *rememberSecondWriteWriter) Write(p []byte) (int, error) {
145146
if n.writecount == 2 {
146147
n.idx = n.pos
147148
n.end = n.pos + len(p)
149+
n.pos += len(p)
150+
return len(p), io.EOF
148151
}
149152
n.pos += len(p)
150153
return len(p), nil
@@ -155,6 +158,8 @@ func (n *rememberSecondWriteWriter) WriteString(s string) (int, error) {
155158
if n.writecount == 2 {
156159
n.idx = n.pos
157160
n.end = n.pos + len(s)
161+
n.pos += len(s)
162+
return len(s), io.EOF
158163
}
159164
n.pos += len(s)
160165
return len(s), nil

0 commit comments

Comments
 (0)