From f01486a8e43424f5efcb257ea0194ec2da974396 Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Sat, 3 May 2025 12:00:29 -0700 Subject: [PATCH] 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 Commit-Queue: Konstantin Shcheglov Reviewed-by: Konstantin Shcheglov --- pkg/analyzer/lib/src/dart/ast/ast.dart | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart index 1f81ad4853f..38cda16ac5f 100644 --- a/pkg/analyzer/lib/src/dart/ast/ast.dart +++ b/pkg/analyzer/lib/src/dart/ast/ast.dart @@ -1053,17 +1053,13 @@ sealed class AstNodeImpl implements AstNode { _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 @@ sealed class AstNodeImpl implements AstNode { Iterable 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;