Skip to content

Commit f01486a

Browse files
bwilkersonCommit Queue
authored andcommitted
Improve the offset, length, and end getters in AstNodeImpl
While this does improve the performance of these getters (by about 5%) the purpose of this CL is just to clean up the implementation of them. It bothers my that they (especially `end`) are using such an indirect way of computing their values. Change-Id: I384890a9adc108c4c67b906864201edee9aa8598 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426400 Auto-Submit: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent ba40d9b commit f01486a

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,28 +1053,21 @@ sealed class AstNodeImpl implements AstNode {
10531053
_childEntities.syntacticEntities;
10541054

10551055
@override
1056-
int get end => offset + length;
1056+
int get end => endToken.end;
10571057

10581058
@override
10591059
bool get isSynthetic => false;
10601060

10611061
@override
1062-
int get length {
1063-
var beginToken = this.beginToken;
1064-
var endToken = this.endToken;
1065-
return endToken.offset + endToken.length - beginToken.offset;
1066-
}
1062+
int get length => end - offset;
10671063

10681064
/// The properties (tokens and nodes) of this node, with names, in the order
10691065
/// in which these entities should normally appear, not necessarily in the
10701066
/// order they really are (because of recovery).
10711067
Iterable<ChildEntity> get namedChildEntities => _childEntities.entities;
10721068

10731069
@override
1074-
int get offset {
1075-
var beginToken = this.beginToken;
1076-
return beginToken.offset;
1077-
}
1070+
int get offset => beginToken.offset;
10781071

10791072
@override
10801073
AstNode? get parent => _parent;

0 commit comments

Comments
 (0)