Skip to content

Commit 06019fd

Browse files
committed
Replace monospace hack with duospace calc
... now that the correct duospace width calculations are much faster (and thus only ~10% slower than doing it wrong).
1 parent 0588d6b commit 06019fd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/Terminal/Widgets/Viewer/Tree.rakumod

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,16 @@ class Terminal::Widgets::Viewer::Tree
111111
# self.flat-line-cache.map({ $locale.width($_) }).max
112112

113113
# XXXX: HACK while refactoring content model
114+
use Text::MiscUtils::Layout;
115+
state %width-cache;
116+
114117
my $debug = +($*DEBUG // 0);
115118
my $t0 = now;
116-
my $max = self.flat-line-cache.map({ .[0].text.chars
117-
+ .[1].text.chars }).max;
119+
my $max = self.flat-line-cache.map({
120+
# Only prefix has low enough cardinality to cache
121+
(%width-cache{.[0].text} //= duospace-width-core(.[0].text, 0))
122+
+ duospace-width-core(.[1].text, 0)
123+
}).max;
118124
note sprintf("max-line-width: %.3fms (%d elems)",
119125
1000 * (now - $t0), @!flat-line-cache.elems) if $debug;
120126
$max

0 commit comments

Comments
 (0)