@@ -25,8 +25,6 @@ internal interface TextCanvas {
25
25
operator fun get (row : Int , column : Int ): TextPixel
26
26
}
27
27
28
- private val blankPixel = TextPixel (' ' )
29
-
30
28
internal class TextSurface (
31
29
override val width : Int ,
32
30
override val height : Int ,
@@ -37,19 +35,32 @@ internal class TextSurface(
37
35
38
36
private val cells = Array (width * height) { TextPixel (' ' ) }
39
37
38
+ /* *
39
+ * It is used in places where the [TextPixel] state is not important
40
+ * and it can change.
41
+ */
42
+ private val reusableDirtyPixel: TextPixel = newBlankPixel
43
+
44
+ /* *
45
+ * It is used in places where it is important that the [TextPixel]
46
+ * has its original state and **will not change**.
47
+ */
48
+ private val reusableBlankPixel: TextPixel = newBlankPixel
49
+
40
50
override operator fun get (row : Int , column : Int ): TextPixel {
41
51
val x = translationX + column
42
52
val y = row + translationY
43
- check(x in 0 until width)
44
- check(y in 0 until height)
53
+ if (x >= width || y >= height || x < 0 || y < 0 ) {
54
+ return reusableDirtyPixel
55
+ }
45
56
return cells[y * width + x]
46
57
}
47
58
48
59
fun appendRowTo (appendable : Appendable , row : Int ) {
49
60
// Reused heap allocation for building ANSI attributes inside the loop.
50
61
val attributes = mutableIntListOf()
51
62
52
- var lastPixel = blankPixel
63
+ var lastPixel = reusableBlankPixel
53
64
54
65
val rowStart = row * width
55
66
val rowStop = rowStart + width
@@ -165,6 +176,11 @@ internal class TextSurface(
165
176
}
166
177
}
167
178
179
+ /* *
180
+ * Returns always a new blank [TextPixel].
181
+ */
182
+ private inline val newBlankPixel: TextPixel get() = TextPixel (' ' )
183
+
168
184
internal class TextPixel (var codePoint : Int ) {
169
185
var background: Color = Color .Unspecified
170
186
var foreground: Color = Color .Unspecified
0 commit comments