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 <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart
index 1f81ad4..38cda16 100644
--- a/pkg/analyzer/lib/src/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/src/dart/ast/ast.dart
@@ -1053,17 +1053,13 @@
_childEntities.syntacticEntities;
@override
- int get end => offset + length;
+ int get end => endToken.end;
@override
bool get isSynthetic => false;
@override
- int get length {
- var beginToken = this.beginToken;
- var endToken = this.endToken;
- return endToken.offset + endToken.length - beginToken.offset;
- }
+ int get length => end - offset;
/// The properties (tokens and nodes) of this node, with names, in the order
/// in which these entities should normally appear, not necessarily in the
@@ -1071,10 +1067,7 @@
Iterable<ChildEntity> get namedChildEntities => _childEntities.entities;
@override
- int get offset {
- var beginToken = this.beginToken;
- return beginToken.offset;
- }
+ int get offset => beginToken.offset;
@override
AstNode? get parent => _parent;