@@ -18,6 +18,11 @@ import de.cketti.codepoints.appendCodePoint
18
18
19
19
private val blankPixel = TextPixel (' ' )
20
20
21
+ /* *
22
+ * Returns always a new blank [TextPixel].
23
+ */
24
+ private inline fun newBlankPixel (): TextPixel = TextPixel (' ' )
25
+
21
26
public interface TextCanvas {
22
27
public val height: Int
23
28
public val width: Int
@@ -35,19 +40,32 @@ internal class TextSurface(
35
40
36
41
private val cells = Array (width * height) { TextPixel (' ' ) }
37
42
43
+ /* *
44
+ * It is used in places where the [TextPixel] state is not important
45
+ * and it can change.
46
+ */
47
+ private val reusableDirtyPixel: TextPixel = newBlankPixel()
48
+
49
+ /* *
50
+ * It is used in places where it is important that the [TextPixel]
51
+ * has its original state and **will not change**.
52
+ */
53
+ private val reusableBlankPixel: TextPixel = newBlankPixel()
54
+
38
55
operator fun get (row : Int , column : Int ): TextPixel {
39
56
val x = translationX + column
40
57
val y = row + translationY
41
- check(x in 0 until width)
42
- check(y in 0 until height)
58
+ if (x >= width || y >= height || x < 0 || y < 0 ) {
59
+ return reusableDirtyPixel
60
+ }
43
61
return cells[y * width + x]
44
62
}
45
63
46
64
override fun appendRowTo (appendable : Appendable , row : Int , ansiLevel : AnsiLevel ) {
47
65
// Reused heap allocation for building ANSI attributes inside the loop.
48
66
val attributes = mutableIntListOf()
49
67
50
- var lastPixel = blankPixel
68
+ var lastPixel = reusableBlankPixel
51
69
52
70
val rowStart = row * width
53
71
val rowStop = rowStart + width
0 commit comments