about summary refs log tree commit diff stats
path: root/src/io/buffer.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-11-16 19:23:31 +0100
committerbptato <nincsnevem662@gmail.com>2021-11-19 21:52:19 +0100
commitcd28af13fc6753792b3b9571abba5943f90d021e (patch)
tree5b7c829f70fe8bf81b11b959c1ea92e34db125d5 /src/io/buffer.nim
parentbbd416f5ffba5ba5e5d41869042cef1f85323146 (diff)
downloadchawan-cd28af13fc6753792b3b9571abba5943f90d021e.tar.gz
Various performance optimizations (...part two)
Diffstat (limited to 'src/io/buffer.nim')
-rw-r--r--src/io/buffer.nim93
1 files changed, 53 insertions, 40 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index 9196504b..da33ae34 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -200,6 +200,7 @@ proc clearDisplay*(buffer: Buffer) =
   buffer.display = newFixedGrid(buffer.width, buffer.height)
 
 proc refreshDisplay*(buffer: Buffer) =
+  var r: Rune
   var y = 0
   buffer.clearDisplay()
 
@@ -207,21 +208,31 @@ proc refreshDisplay*(buffer: Buffer) =
                            buffer.lastVisibleLine - 1]:
     var w = 0
     var i = 0
+    var j = 0
     while w < buffer.fromx and i < line.len:
-      w += line[i].rune.width()
-      inc i
+      fastRuneAt(line.str, i, r)
+      w += r.width()
+      inc j
 
     let dls = y * buffer.width
-    var j = 0
+    var k = 0
     var n = 0
-    while w < buffer.fromx + buffer.width and i < line.len:
-      w += line[i].rune.width()
-      if line[i].rune.width() == 0 and j != 0:
+    var cf = line.findFormat(j)
+    var nf = line.findNextFormat(j)
+    while w < buffer.fromx + buffer.width and i < line.str.len:
+      fastRuneAt(line.str, i, r)
+      w += r.width()
+      if nf.pos != -1 and nf.pos <= j:
+        cf = nf
+        nf = line.findNextFormat(j)
+      if r.width() == 0 and k != 0:
         inc n
-      buffer.display[dls + j - n].runes.add(line[i].rune)
-      buffer.display[dls + j - n].formatting = line[i].formatting
-      j += line[i].rune.width()
-      inc i
+      buffer.display[dls + k - n].runes.add(r)
+      if cf.pos != -1:
+        buffer.display[dls + k - n].formatting = cf.formatting
+        buffer.display[dls + k - n].nodes = cf.nodes
+      k += r.width()
+      inc j
 
     inc y
 
@@ -528,7 +539,7 @@ proc refreshTermAttrs*(buffer: Buffer): bool =
   if newAttrs != buffer.attrs:
     buffer.attrs = newAttrs
     buffer.width = newAttrs.width
-    buffer.height = newAttrs.height
+    buffer.height = newAttrs.height - 1
     return true
   return false
 
@@ -546,46 +557,47 @@ func formatFromLine(line: CSSRowBox): Formatting =
     result.strike = true
 
 proc setRowBox(buffer: Buffer, line: CSSRowBox) =
-  if line.runes.len == 0:
-    return
+  var r: Rune
 
   let x = line.x
   let y = line.y
 
-  let format = line.formatFromLine()
   while buffer.lines.len <= y:
     buffer.addLine()
 
   var i = 0
+  var j = 0
   var cx = 0
-  while cx < x and i < buffer.lines[y].len:
-    cx += buffer.lines[y][i].rune.width()
-    inc i
+  while cx < x and i < buffer.lines[y].str.len:
+    fastRuneAt(buffer.lines[y].str, i, r)
+    cx += r.width()
+    inc j
 
-  var oline = buffer.lines[y].subline(i)
-  buffer.lines[y].setLen(i)
-  var j = 0
-  var nx = cx
+  let ostr = buffer.lines[y].str.substr(i)
+  let oformats = buffer.lines[y].formats.subformats(j)
+  buffer.lines[y].str.setLen(i)
+  buffer.lines[y].setLen(j)
 
-  #TODO not sure
-  while nx < x:
-    buffer.lines.addCell(y, Rune(' '))
-    inc nx
+  buffer.lines.addFormat(y, j, line.formatFromLine(), line.nodes)
 
-  buffer.lines.addFormat(y, format)
-  while j < line.runes.len:
-    buffer.lines.addCell(y, line.runes[j])
-    nx += line.runes[j].width()
-    inc j
+  var nx = cx
+  if nx < x:
+    buffer.lines[y].str &= ' '.repeat(x - nx)
+    nx = x
+
+  buffer.lines[y].str &= line.str
+  nx += line.str.width()
 
   i = 0
-  while cx < nx and i < oline.len:
-    cx += oline[i].rune.width()
-    inc i
+  j = 0
+  while cx < nx and i < ostr.len:
+    fastRuneAt(ostr, i, r)
+    cx += r.width()
+    inc j
 
-  if i < oline.len:
-    let nol = oline.subLine(i)
-    buffer.lines[y].add(nol)
+  if i < ostr.len:
+    let oline = FlexibleLine(str: ostr.substr(i), formats: oformats.subformats(j))
+    buffer.lines[y].add(oline)
 
 proc updateCursor(buffer: Buffer) =
   if buffer.fromy > buffer.lastVisibleLine - 1:
@@ -633,6 +645,7 @@ proc renderPlainText*(buffer: Buffer, text: string) =
   while i < text.len:
     if text[i] == '\n':
       buffer.addLine()
+      buffer.lines.addFormat(buffer.lines.len - 1, format)
       inc y
       x = 0
       inc i
@@ -640,17 +653,17 @@ proc renderPlainText*(buffer: Buffer, text: string) =
       inc i
     elif text[i] == '\t':
       for i in 0..8:
-        buffer.lines.addCell(Rune(' '), format)
+        buffer.lines[^1].str &= ' '
       inc i
     elif text[i] == '\e':
       i = format.parseAnsiCode(text, i)
     elif text[i].isControlChar():
-      buffer.lines.addCell(Rune('^'), format)
-      buffer.lines.addCell(Rune(text[i].getControlLetter()), format)
+      buffer.lines.addCell(Rune('^'))
+      buffer.lines.addCell(Rune(text[i].getControlLetter()))
       inc i
     else:
       fastRuneAt(text, i, r)
-      buffer.lines.addCell(r, format)
+      buffer.lines.addCell(r)
   buffer.updateCursor()
 
 proc renderDocument*(buffer: Buffer) =
ef='#n382'>382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
mu/blame/html/linux/bootstrap/002test.cc.html?h=hlt&id=62a244211024a8367332541c571621883c05bcce'>^
5fe060d5 ^

d3a9db3a ^
3350c34a ^
5fe060d5 ^


3350c34a ^
5fe060d5 ^






3350c34a ^
5fe060d5 ^
6e1eeeeb ^
3350c34a ^
5fe060d5 ^












6e1eeeeb ^

c504ca56 ^
6e1eeeeb ^
3350c34a ^
6e1eeeeb ^



3350c34a ^
6e1eeeeb ^


8aeb85f0 ^
6e1eeeeb ^
3350c34a ^
6e1eeeeb ^





3350c34a ^
6e1eeeeb ^



3350c34a ^

c504ca56 ^
3350c34a ^
c504ca56 ^



3350c34a ^















672e3e50 ^


a654e4ec ^
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