Skip to content

Commit 3ff6eaf

Browse files
author
c
committed
save a few unnecessary blank characters
1 parent aa73b27 commit 3ff6eaf

File tree

6 files changed

+50
-41
lines changed

6 files changed

+50
-41
lines changed

tests/bench1.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
"\
2626
2727
bc╶┴─╮
28-
╰─┰──╯
29-
━━━━━━△━━◀━━━┛
28+
╰─┰──╯
29+
━━━━━━△━━◀━━━┛
3030
")

tests/bench2.el

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
(uniline-bench
2323
"C-c C-c i n i t i a l SPC t e x t e <backspace> <return> SPC SPC g o o d <return> C-a M-x u n i l i n e - m o d e RET <up> <up> C-SPC <down> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <insert> <down> <down> <right> <right> <right> R <end> <return> <kp-subtract> <right> q <return> <left> <kp-subtract> <down> <left> <left> <return> <up> <up> <right> <right> <down> <kp-subtract> <up> <right> <right> <right> <up> <up> <up> <return> <down> <down> <down> <up> <up> <right> <down> <down> <down> C-SPC <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <up> <up> <up> <insert> <up> <down> <down> c <end> C-SPC <insert> y <return> <return> <down> <down> <down> <right> <right> <right> <right> = <down> <left> <left> <left> <left> <left> <left> <insert> s s s <left> <left> <left> <left> <left> <insert> o <left> <left> <left> <left> <left> <left> <up>"
2424
"\
25-
25+
2626
27-
╭────────────╮ ╭──╯ ╭────────────╮ ╭──╯
28-
│initial text│ q │initial text│ q
29-
││ good ├─╯ ││ good ├─╯
30-
╰──────╥─────╯ ╰───╥────────╯
27+
╭────────────╮ ╭──╯ ╭────────────╮ ╭──╯
28+
│initial text│ q │initial text│ q
29+
││ good ├─╯ ││ good ├─╯
30+
╰──────╥─────╯ ╰───╥────────╯
3131
╚═════·════▫═════╝
3232
")

tests/bench4.el

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
"<return> <down> <right> <right> <right> <right> <down> <down> <right> <right> <right> <right> <down> <left> M <left> = <up> <up> <up> <right> <right> <right> <right> <right> <right> <down> <down> <down> <left> <left> <insert> a <left> <left> <left> <left> <left> <left> <left> <insert> a a a <left> <down> <down> <down> <right> <right> <right> <right> <up> <up> <up> <return> <up> <up> <right> <right> <insert> s <down> <right> <right> <insert> s s <down> <down> <down> <left> <left> <left> <left> <left> <left> <insert> x <up> <insert> o o o o o <up> <up> <up> <up> <right> <right> <right> <right> <right> <right> <right> <right> <right> C-SPC <down> <down> <down> <down> <down> <down> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <insert> c <right> <return> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <up> <up> <up> <up> <up> <up> C-SPC <insert> y <return>"
2424
"\
2525
26-
╔═════╗ ╔═════╗
27-
║ □ ║ ║ □ ║
28-
║ ■ ║ ║ ■ ║
29-
╔←══M═══◁═╝ ╔←══M═══◁═╝
30-
║ ◦ ║ ║ ◦ ║
31-
║ ╳ ║ ║ ╳ ║
32-
╚═══╝ ╚═══╝
33-
26+
╔═════╗ ╔═════╗
27+
║ □ ║ ║ □ ║
28+
║ ■ ║ ║ ■ ║
29+
╔←══M═══◁═╝ ╔←══M═══◁═╝
30+
║ ◦ ║ ║ ◦ ║
31+
║ ╳ ║ ║ ╳ ║
32+
╚═══╝ ╚═══╝
33+
3434
")

tests/bench5.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
2626
2727
aaaa aa╭─────╦╤╤══aaaaaaaa
28-
aaaa │aaa ║┏┿━━━┓aaaaaaaa
29-
aaa│ aaaa║┃│aaa┃║ aaaaaaaa
30-
a╰─────╫╂╯ a┃a aaaaaaaa
31-
║┗━━━━┛║
28+
aaaa │aaa ║┏┿━━━┓aaaaaaaa
29+
aaa│ aaaa║┃│aaa┃║ aaaaaaaa
30+
a╰─────╫╂╯ a┃a aaaaaaaa
31+
║┗━━━━┛║
3232
╚══════╝
3333
")

tests/uniline-bench.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ RESULT is a string representing the expected result."
7171
(switch-to-buffer-other-window "*uniline-expected*")
7272
(insert result)
7373
(goto-char (point-min))
74-
(compare-windows nil)))
74+
(compare-windows nil))
75+
76+
uniline-bench-result)
7577

7678
(defun uniline-bench-create ()
7779
"Interactively create a bench.

uniline.el

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,11 @@ Exchange left with right, up with down."
149149
('uniline--direction-lf'uniline--direction-ri→)
150150
(_ (error "Bad direction")))))
151151

152-
(defun uniline--move-to-column (x)
152+
(defsubst uniline--move-to-column (x)
153153
"Move to column X staying on the same line.
154-
Add blanks if line is too short: ensure that cursor
155-
points to a character, not \\n.
154+
Add blanks if line is too short.
156155
Move to 0 if X negative."
157-
(let ((x (max x 0))) ;; let is faster than setq when byte-compiled
158-
(move-to-column (1+ x) t)
159-
(move-to-column x t)))
156+
(move-to-column (max x 0) t))
160157

161158
(defun uniline--move-to-delta-column (x)
162159
"Move X characters, staying on the same line.
@@ -195,11 +192,10 @@ or blank characters at the end of target line.
195192
Y=0 means first line in buffer."
196193
(move-to-column
197194
(prog1
198-
(1+ (current-column))
195+
(current-column)
199196
(goto-char (point-min))
200197
(uniline--forward-line-force y))
201-
t)
202-
(backward-char))
198+
t))
203199

204200
(defun uniline--move-to-delta-line (y)
205201
"Move Y lines while staying on the same column.
@@ -208,10 +204,9 @@ or blank characters at the end of target line.
208204
Y may be negative to move backward."
209205
(move-to-column
210206
(prog1
211-
(1+ (current-column))
207+
(current-column)
212208
(uniline--forward-line-force y))
213-
t)
214-
(backward-char))
209+
t))
215210

216211
(defun uniline--move-to-col-lin (y x)
217212
"Move to line Y and column X.
@@ -221,8 +216,7 @@ Y=0 means first line of buffer.
221216
X=0 means first column of buffer."
222217
(goto-char (point-min))
223218
(uniline--forward-line-force y)
224-
(move-to-column (1+ x) t)
225-
(move-to-column x t))
219+
(uniline--move-to-column x))
226220

227221
(eval-when-compile ; not needed at runtime
228222
(defmacro uniline--move-in-direction (dir &optional nb)
@@ -255,6 +249,14 @@ In the bottom & right directions the buffer is infinite."
255249
('uniline--direction-lf← '(bolp))
256250
(_ (error "Bad direction")))))
257251

252+
(defun uniline--char-after ()
253+
"Same as `char-after', except for right and bottom edges of buffer.
254+
Outside the buffer, return a blank character."
255+
(let ((c (char-after)))
256+
(if (or (not c) (eq c ?\n))
257+
? ;; eol & eob are considered blank
258+
c)))
259+
258260
;;;╭─────────────────────────────────────────────────────╮
259261
;;;│Reference tables of ┼ 4 half-lines UNICODE characters│
260262
;;;╰─────────────────────────────────────────────────────╯
@@ -1015,7 +1017,7 @@ north-east, south-west, etc.
10151017
(or
10161018
(eolp)
10171019
(delete-char 1))
1018-
(insert char)
1020+
(insert (if (eq char ?\n) ? char))
10191021
(backward-char))
10201022

10211023
;;;╭────────────────────────────────────────────────────────╮
@@ -1037,7 +1039,9 @@ nil: no action except cursor movements
10371039
"Return a bit pattern (a 4halfs).
10381040
It represents a UNICODE character like ┬ found at (point).
10391041
Return nil if the character is not a 4halfs character."
1040-
(aref uniline--char-to-4halfs (or (char-after) ? ))))
1042+
(aref
1043+
uniline--char-to-4halfs
1044+
(uniline--char-after))))
10411045

10421046
(eval-when-compile ; not needed at runtime
10431047
(defsubst uniline--insert-4halfs (4halfs)
@@ -1080,7 +1084,7 @@ character at point."
10801084
(uniline--insert-char ? ))
10811085
(let ((bits
10821086
(or
1083-
(aref uniline--block-char-to-4quadb (char-after))
1087+
(aref uniline--block-char-to-4quadb (uniline--char-after))
10841088
(and force 0))))
10851089
(if bits
10861090
(uniline--insert-char
@@ -1092,7 +1096,7 @@ character at point."
10921096
"Helper function to clear half a quadrant-block at point.
10931097
Assume that point is on a quadrant-block character.
10941098
Clear the half of this character pointing in DIR direction."
1095-
`(let ((bits (aref uniline--block-char-to-4quadb (char-after))))
1099+
`(let ((bits (aref uniline--block-char-to-4quadb (uniline--char-after))))
10961100
(if bits
10971101
(uniline--insert-char
10981102
(aref
@@ -1372,7 +1376,7 @@ Then the leakage of the two glyphs fills in E:
13721376
repeat ,size
13731377
do
13741378
(setq hand
1375-
(prog1 (char-after)
1379+
(prog1 (uniline--char-after)
13761380
(uniline--insert-char hand)))
13771381
(uniline--move-in-direction ,dir))
13781382
(uniline--insert-char hand))))))
@@ -1783,7 +1787,7 @@ of the same command."
17831787
(setq repeat (- repeat)
17841788
back (not back)))
17851789
(let ((line ; something like (3 x ((a ?▲ ?▶ ?▼ ?◀) (a ?↑ ?→ ?↓ ?←) …))
1786-
(gethash (char-after)
1790+
(gethash (uniline--char-after)
17871791
(if back
17881792
uniline--glyphs-reverse-hash-bw
17891793
uniline--glyphs-reverse-hash-fw))))
@@ -1890,7 +1894,10 @@ See `uniline--insert-glyph'."
18901894

18911895
(defun uniline--rotate-arrow (dir)
18921896
"Rotate an arrow so it points toward DIR."
1893-
(let ((ligne (gethash (char-after) uniline--glyphs-reverse-hash-fw)))
1897+
(let ((ligne
1898+
(gethash
1899+
(uniline--char-after)
1900+
uniline--glyphs-reverse-hash-fw)))
18941901
(when (car ligne) ;; if (point) is on a directional arrow
18951902
(uniline--insert-char ;; then change its direction
18961903
(nth (1+ dir) (cadr ligne))))))

0 commit comments

Comments
 (0)