diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2015-01-24 12:28:00 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-01-24 12:28:00 +0900 |
commit | 71a7b3a26f344130736ca9d2e8f4210edffec257 (patch) | |
tree | a409a62f8ff63e7bf08815ea8281dc0c3743d255 /src | |
parent | a47c06cb612a392b8c1b9a5c92782510d48fa746 (diff) |
Improve rendering performance by caching rune widths
Related: 8bead4a
Diffstat (limited to 'src')
-rw-r--r-- | src/terminal.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/terminal.go b/src/terminal.go index e1eb4c29..e9de6868 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -62,6 +62,7 @@ func (a ByTimeOrder) Less(i, j int) bool { } var _spinner = []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`} +var _runeWidths = make(map[rune]int) const ( reqPrompt util.EventType = iota @@ -176,8 +177,12 @@ func (t *Terminal) output() { func runeWidth(r rune, prefixWidth int) int { if r == '\t' { return 8 - prefixWidth%8 + } else if w, found := _runeWidths[r]; found { + return w } else { - return runewidth.RuneWidth(r) + w := runewidth.RuneWidth(r) + _runeWidths[r] = w + return w } } |