mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-23 06:12:00 +01:00
Cache hash codes for Sass strings and numbers
These values are often stored in maps, so caching their hash codes seems to be net valuable.
This commit is contained in:
parent
fa2576449e
commit
6069708a83
@ -1,3 +1,7 @@
|
|||||||
|
## 1.43.3
|
||||||
|
|
||||||
|
* Improve performance.
|
||||||
|
|
||||||
## 1.43.2
|
## 1.43.2
|
||||||
|
|
||||||
* Improve the error message when the default namespace of a `@use` rule is not
|
* Improve the error message when the default namespace of a `@use` rule is not
|
||||||
|
@ -181,6 +181,12 @@ abstract class SassNumber extends Value {
|
|||||||
/// integer value, or [assertInt] to do both at once.
|
/// integer value, or [assertInt] to do both at once.
|
||||||
final num value;
|
final num value;
|
||||||
|
|
||||||
|
/// The cached hash code for this number, if it's been computed.
|
||||||
|
///
|
||||||
|
/// @nodoc
|
||||||
|
@protected
|
||||||
|
int? hashCache;
|
||||||
|
|
||||||
/// This number's numerator units.
|
/// This number's numerator units.
|
||||||
List<String> get numeratorUnits;
|
List<String> get numeratorUnits;
|
||||||
|
|
||||||
@ -826,7 +832,7 @@ abstract class SassNumber extends Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int get hashCode => fuzzyHashCode(value *
|
int get hashCode => hashCache ??= fuzzyHashCode(value *
|
||||||
_canonicalMultiplier(numeratorUnits) /
|
_canonicalMultiplier(numeratorUnits) /
|
||||||
_canonicalMultiplier(denominatorUnits));
|
_canonicalMultiplier(denominatorUnits));
|
||||||
|
|
||||||
|
@ -160,5 +160,6 @@ class SingleUnitSassNumber extends SassNumber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int get hashCode => fuzzyHashCode(value * canonicalMultiplierForUnit(_unit));
|
int get hashCode =>
|
||||||
|
hashCache ??= fuzzyHashCode(value * canonicalMultiplierForUnit(_unit));
|
||||||
}
|
}
|
||||||
|
@ -142,5 +142,5 @@ class UnitlessSassNumber extends SassNumber {
|
|||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
other is UnitlessSassNumber && fuzzyEquals(value, other.value);
|
other is UnitlessSassNumber && fuzzyEquals(value, other.value);
|
||||||
|
|
||||||
int get hashCode => fuzzyHashCode(value);
|
int get hashCode => hashCache ??= fuzzyHashCode(value);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,9 @@ class SassString extends Value {
|
|||||||
/// efficient.
|
/// efficient.
|
||||||
late final int sassLength = text.runes.length;
|
late final int sassLength = text.runes.length;
|
||||||
|
|
||||||
|
/// The cached hash code for this number, if it's been computed.
|
||||||
|
int? _hashCache;
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@internal
|
@internal
|
||||||
bool get isSpecialNumber {
|
bool get isSpecialNumber {
|
||||||
@ -189,7 +192,7 @@ class SassString extends Value {
|
|||||||
|
|
||||||
bool operator ==(Object other) => other is SassString && text == other.text;
|
bool operator ==(Object other) => other is SassString && text == other.text;
|
||||||
|
|
||||||
int get hashCode => text.hashCode;
|
int get hashCode => _hashCache ??= text.hashCode;
|
||||||
|
|
||||||
/// Throws a [SassScriptException] with the given [message].
|
/// Throws a [SassScriptException] with the given [message].
|
||||||
SassScriptException _exception(String message, [String? name]) =>
|
SassScriptException _exception(String message, [String? name]) =>
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
## 1.0.0-beta.17
|
||||||
|
|
||||||
|
* No user-visible changes.
|
||||||
|
|
||||||
## 1.0.0-beta.16
|
## 1.0.0-beta.16
|
||||||
|
|
||||||
* No user-visible changes.
|
* No user-visible changes.
|
||||||
|
@ -2,7 +2,7 @@ name: sass_api
|
|||||||
# Note: Every time we add a new Sass AST node, we need to bump the *major*
|
# Note: Every time we add a new Sass AST node, we need to bump the *major*
|
||||||
# version because it's a breaking change for anyone who's implementing the
|
# version because it's a breaking change for anyone who's implementing the
|
||||||
# visitor interface(s).
|
# visitor interface(s).
|
||||||
version: 1.0.0-beta.16
|
version: 1.0.0-beta.17
|
||||||
description: Additional APIs for Dart Sass.
|
description: Additional APIs for Dart Sass.
|
||||||
homepage: https://github.com/sass/dart-sass
|
homepage: https://github.com/sass/dart-sass
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ environment:
|
|||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
sass: 1.43.2
|
sass: 1.43.3
|
||||||
|
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
sass: {path: ../..}
|
sass: {path: ../..}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: sass
|
name: sass
|
||||||
version: 1.43.2
|
version: 1.43.3
|
||||||
description: A Sass implementation in Dart.
|
description: A Sass implementation in Dart.
|
||||||
homepage: https://github.com/sass/dart-sass
|
homepage: https://github.com/sass/dart-sass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user