Skip to content

Commit

Permalink
Optimize values getter for css.Declaration (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
daohoangson authored Jan 13, 2024
1 parent 096866c commit df3245b
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/core/lib/src/external/csslib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,17 @@ extension CssAngleTermExtension on css.AngleTerm {

/// An extension on [css.Declaration].
extension CssDeclarationExtension on css.Declaration {
static Expando<List<css.Expression>>? _expando;

/// Returns CSS expressions.
///
/// Collecting expressions is a non-trivial task but the result is cached
/// so it's safe to call this again and again.
List<css.Expression> get values {
final expando = _expando ??= Expando();
final existing = expando[this];
if (existing != null) {
return existing;
final scoped = expression;
if (scoped is css.Expressions) {
return scoped.expressions;
}

return expando[this] = _ExpressionsCollector.collect(this);
return const [];
}

/// Returns the CSS expression.
Expand Down

1 comment on commit df3245b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.