Skip to content

Commit deb0e10

Browse files
committed
Simplify code
The readCell function was introduced in e659668 only for this purpose. We don't need it because: - the extra check for c.chr == 0 is not needed; if there is already a null cell at the line end, we needn't write it again. There is no difference between a null cell and a printable cell in this regard - the only check that's left is for the coordinates; we know that y is valid, and x is not less than 0, so the only check we need is for x against the length of the line.
1 parent 1e9abd0 commit deb0e10

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

view.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -726,14 +726,6 @@ func (v *View) writeCells(x, y int, cells []cell) {
726726
v.lines[y] = line[:newLen]
727727
}
728728

729-
// readCell gets cell at specified location (x, y)
730-
func (v *View) readCell(x, y int) (cell, bool) {
731-
if y < 0 || y >= len(v.lines) || x < 0 || x >= len(v.lines[y]) {
732-
return cell{}, false
733-
}
734-
return v.lines[y][x], true
735-
}
736-
737729
// Write appends a byte slice into the view's internal buffer. Because
738730
// View implements the io.Writer interface, it can be passed as parameter
739731
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
@@ -764,7 +756,7 @@ func (v *View) writeRunes(p []rune) {
764756

765757
finishLine := func() {
766758
v.autoRenderHyperlinksInCurrentLine()
767-
if c, ok := v.readCell(v.wx, v.wy); !ok || c.chr == 0 {
759+
if v.wx >= len(v.lines[v.wy]) {
768760
v.writeCells(v.wx, v.wy, []cell{{
769761
chr: 0,
770762
fgColor: 0,

0 commit comments

Comments
 (0)