about summary refs log tree commit diff stats
path: root/src/server
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-11-18 19:52:35 +0100
committerbptato <nincsnevem662@gmail.com>2023-11-20 15:47:31 +0100
commitdbb60a3cb0c1ada39692426e1b5a45245b3b791d (patch)
tree2350a39a39342e8a4d7bb201fb556d83169c6537 /src/server
parent3b09d016a262abef593fe748392d4c3a655438d1 (diff)
downloadchawan-dbb60a3cb0c1ada39692426e1b5a45245b3b791d.tar.gz
buffer: optimize findPrevLink
It's better to not do it perfectly in 100% of all cases than to
loop through the entire document in all cases.
Diffstat (limited to 'src/server')
-rw-r--r--src/server/buffer.nim8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 3a458cc4..97acc8e2 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -412,6 +412,8 @@ proc findPrevLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.pr
     for iy in countdown(ly - 1, 0):
       let line = buffer.lines[iy]
       i = line.formats.len - 1
+      let oly = iy
+      let olx = lx
       while i >= 0:
         let format = line.formats[i]
         let nl = format.node.getClickable()
@@ -419,6 +421,12 @@ proc findPrevLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.pr
           ly = iy
           lx = format.pos
         dec i
+      if iy == oly and olx == lx:
+        # Assume multiline anchors are always placed on consecutive lines.
+        # This is not true, but otherwise we would have to loop through
+        # the entire document, which would be rather inefficient. TODO: find
+        # an efficient and correct way to do this.
+        break
 
   while i >= 0:
     let format = line.formats[i]
cdeb9cbb3a4718d8b0d707e0864c00aca7a580'>^
7ff4bdbf ^












331ebf78 ^



ea87d005 ^
331ebf78 ^

7ff4bdbf ^
331ebf78 ^
7ff4bdbf ^

331ebf78 ^


7ff4bdbf ^

331ebf78 ^













ea87d005 ^
331ebf78 ^














ea87d005 ^
331ebf78 ^
















7ff4bdbf ^

331ebf78 ^




















ea62273c ^
331ebf78 ^























ea62273c ^


ea87d005 ^
331ebf78 ^












ea62273c ^

331ebf78 ^






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208