Skip to content

Commit 4ef8d74

Browse files
committed
Micro-optimize attribute lookup in TextContent
1 parent f53733b commit 4ef8d74

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

lib/Terminal/Widgets/TextContent.rakumod

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class RenderSpan is export {
4646
#| Break a single RenderSpan into list of RenderSpans, each containing only
4747
#| one line (delimited by textual newlines as usual for Str.lines)
4848
method lines(Bool:D :$chomp = True) {
49-
$.text.lines(:$chomp).map({ RenderSpan.new(text => $_, :$.color, :$.string-span) })
49+
$!text.lines(:$chomp).map({ RenderSpan.new(text => $_, :$!color, :$!string-span) })
5050
}
5151

5252
#| Stringify to an SGR-escaped string instead of rendering into a widget's
@@ -84,23 +84,23 @@ class StringSpan does SemanticSpan {
8484
#| Render the string into a RenderSpan according to its attributes
8585
method render(--> RenderSpan:D) {
8686
# XXXX: Hack: Just transfer over the color attribute
87-
RenderSpan.new(string-span => self, text => $.string,
88-
color => %.attributes<color> // '')
87+
RenderSpan.new(string-span => self, text => $!string,
88+
color => %!attributes<color> // '')
8989
}
9090

9191
#| Apply current span attributes on top of parent attributes, returning a
9292
#| new StringSpan if needed or self if parent attributes were empty.
9393
#| This method is used primarily as a base case for SpanTree.flatten.
9494
method flatten(%parent-attributes? --> StringSpan:D) {
9595
%parent-attributes
96-
?? self.clone(attributes => merge-attributes(%parent-attributes, %.attributes))
96+
?? self.clone(attributes => merge-attributes(%parent-attributes, %!attributes))
9797
!! self
9898
}
9999

100100
#| Break a single StringSpan into list of StringSpans, each containing only
101101
#| one line (delimited by textual newlines as usual for Str.lines)
102102
method lines(Bool:D :$chomp = True) {
103-
$.string.lines(:$chomp).map({ StringSpan.new(string => $_, :%.attributes) })
103+
$!string.lines(:$chomp).map({ StringSpan.new(string => $_, :%!attributes) })
104104
}
105105

106106
#| Disallow direct .Str without rendering
@@ -124,17 +124,17 @@ class InterpolantSpan does SemanticSpan {
124124
# *which* other variables? Is this encoded in the flag info?
125125
method interpolate(%vars --> StringSpan:D) {
126126
# XXXX: Hack ignoring flags completely for now
127-
my $string = %vars{$.var-name}
128-
// '[MISSING INTERPOLATION VARIABLE ' ~ $.var-name.raku ~ ']';
129-
StringSpan.new(:$.string, :%.attributes);
127+
my $string = %vars{$!var-name}
128+
// '[MISSING INTERPOLATION VARIABLE ' ~ $!var-name.raku ~ ']';
129+
StringSpan.new(:$!string, :%!attributes);
130130
}
131131

132132
#| Apply current span attributes on top of parent attributes, returning a
133133
#| new InterpolantSpan if needed or self if parent attributes were empty.
134134
#| This method is used primarily as a base case for SpanTree.flatten.
135135
method flatten(%parent-attributes? --> InterpolantSpan:D) {
136136
%parent-attributes
137-
?? self.clone(attributes => merge-attributes(%parent-attributes, %.attributes))
137+
?? self.clone(attributes => merge-attributes(%parent-attributes, %!attributes))
138138
!! self
139139
}
140140

@@ -157,8 +157,8 @@ class SpanTree does SemanticText {
157157
#| to override parent attributes or add new ones.
158158
method flatten(%parent-attributes?) {
159159
my %child-base-attributes = merge-attributes(%parent-attributes,
160-
%.attributes);
161-
@.children.map(*.flatten(%child-base-attributes)).flat
160+
%!attributes);
161+
@!children.map(*.flatten(%child-base-attributes)).flat
162162
}
163163

164164
#| Convert from arbitrary tree form to a sequence of Arrays, each of which
@@ -200,7 +200,7 @@ class MarkupString does SemanticText is export {
200200
method parse(--> SpanTree:D) {
201201
# XXXX: Hack returning a SpanTree with just a single StringSpan,
202202
# completely ignoring markup and interpolants
203-
SpanTree.new(children => (StringSpan.new(:$.string),))
203+
SpanTree.new(children => (StringSpan.new(:$!string),))
204204
}
205205

206206
#| Disallow direct .Str without parsing
@@ -290,21 +290,21 @@ class ContentRenderer {
290290
#| for any InterpolantSpans in the list, giving a flat list of StringSpans
291291
multi method flat-string-spans(MarkupString:D $ms) {
292292
$ms.parse.flatten.map: {
293-
.isa(InterpolantSpan) ?? .interpolate(%.vars) !! $_;
293+
.isa(InterpolantSpan) ?? .interpolate(%!vars) !! $_;
294294
};
295295
}
296296

297297
#| Flatten SpanTree -> list of SemanticSpans, interpolate vars for any
298298
#| InterpolantSpans in the list, giving a flat list of StringSpans
299299
multi method flat-string-spans(SpanTree:D $st) {
300300
$st.flatten.map: {
301-
.isa(InterpolantSpan) ?? .interpolate(%.vars) !! $_;
301+
.isa(InterpolantSpan) ?? .interpolate(%!vars) !! $_;
302302
};
303303
}
304304

305305
#| Interpolate InterpolantSpan and pass through resulting StringSpan
306306
multi method flat-string-spans(InterpolantSpan:D $is) {
307-
$is.interpolate(%.vars)
307+
$is.interpolate(%!vars)
308308
}
309309

310310
#| Passthrough existing StringSpan
@@ -329,7 +329,7 @@ class ContentRenderer {
329329
#| Convert SpanTree -> flattened list of RenderSpans
330330
multi method render(SpanTree:D $st) {
331331
$st.flatten.map({
332-
.isa(InterpolantSpan) ?? .interpolate(%.vars).render
332+
.isa(InterpolantSpan) ?? .interpolate(%!vars).render
333333
!! .render
334334
})
335335
}

0 commit comments

Comments
 (0)