From 0b0f196cbe106d0580cf2620e9f7d4848187c6d8 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Mon, 17 Feb 2025 15:01:35 -0600 Subject: [PATCH 1/3] [pub_semver] Reduce memory footprint of non-prerelease versions --- pkgs/pub_semver/CHANGELOG.md | 5 +++++ pkgs/pub_semver/lib/src/version.dart | 12 +++++++++--- pkgs/pub_semver/pubspec.yaml | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pkgs/pub_semver/CHANGELOG.md b/pkgs/pub_semver/CHANGELOG.md index a31fbb2437..47b6f7f0b8 100644 --- a/pkgs/pub_semver/CHANGELOG.md +++ b/pkgs/pub_semver/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.2.0-wip + +- Clarify the `preRelease` and `build` properties of `Version` + return unmodifiable lists. + ## 2.1.5 - Require Dart `3.4.0`. diff --git a/pkgs/pub_semver/lib/src/version.dart b/pkgs/pub_semver/lib/src/version.dart index 90f3d535fd..3f89df50ee 100644 --- a/pkgs/pub_semver/lib/src/version.dart +++ b/pkgs/pub_semver/lib/src/version.dart @@ -70,6 +70,8 @@ class Version implements VersionConstraint, VersionRange { /// This is split into a list of components, each of which may be either a /// string or a non-negative integer. It may also be empty, indicating that /// this version has no pre-release identifier. + /// + /// The returned list is unmodifiable. final List preRelease; /// The build identifier: "foo" in "1.2.3+foo". @@ -77,6 +79,8 @@ class Version implements VersionConstraint, VersionRange { /// This is split into a list of components, each of which may be either a /// string or a non-negative integer. It may also be empty, indicating that /// this version has no build identifier. + /// + /// The returned list is unmodifiable. final List build; /// The original string representation of the version number. @@ -96,8 +100,10 @@ class Version implements VersionConstraint, VersionRange { Version._(this.major, this.minor, this.patch, String? preRelease, String? build, this._text) - : preRelease = preRelease == null ? [] : _splitParts(preRelease), - build = build == null ? [] : _splitParts(build) { + : preRelease = preRelease == null || preRelease.isEmpty + ? const [] + : _splitParts(preRelease), + build = build == null || build.isEmpty ? const [] : _splitParts(build) { if (major < 0) throw ArgumentError('Major version must be non-negative.'); if (minor < 0) throw ArgumentError('Minor version must be non-negative.'); if (patch < 0) throw ArgumentError('Patch version must be non-negative.'); @@ -160,7 +166,7 @@ class Version implements VersionConstraint, VersionRange { // Return an integer part if possible, otherwise return the string // as-is int.tryParse(part) ?? part) - .toList(); + .toList(growable: false); @override bool operator ==(Object other) => diff --git a/pkgs/pub_semver/pubspec.yaml b/pkgs/pub_semver/pubspec.yaml index 536826a4c7..6d95e5754c 100644 --- a/pkgs/pub_semver/pubspec.yaml +++ b/pkgs/pub_semver/pubspec.yaml @@ -1,5 +1,5 @@ name: pub_semver -version: 2.1.5 +version: 2.2.0-wip description: >- Versions and version constraints implementing pub's versioning policy. This is very similar to vanilla semver, with a few corner cases. From ec25148ca1b50ef979a67f786d8ff5a7fb0f92bf Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Wed, 26 Feb 2025 16:10:02 -0600 Subject: [PATCH 2/3] Instead update doc comments to discourage modification --- pkgs/pub_semver/CHANGELOG.md | 9 ++++++--- pkgs/pub_semver/lib/src/version.dart | 10 +++++----- pkgs/pub_semver/lib/src/version_constraint.dart | 6 ++++++ pkgs/pub_semver/lib/src/version_union.dart | 2 ++ pkgs/pub_semver/pubspec.yaml | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pkgs/pub_semver/CHANGELOG.md b/pkgs/pub_semver/CHANGELOG.md index 47b6f7f0b8..4f6fc26fa0 100644 --- a/pkgs/pub_semver/CHANGELOG.md +++ b/pkgs/pub_semver/CHANGELOG.md @@ -1,7 +1,10 @@ -## 2.2.0-wip +## 2.1.6 -- Clarify the `preRelease` and `build` properties of `Version` - return unmodifiable lists. +- Clarify that the lists returned by + the `preRelease` and `build` properties of `Version` and + the `ranges` property of `VersionUnion` should not be modified. +- Note that `VersionConstraint.any` and `VersionConstraint.empty` static fields + shouldn't be reassigned and will be made `final` in a future release. ## 2.1.5 diff --git a/pkgs/pub_semver/lib/src/version.dart b/pkgs/pub_semver/lib/src/version.dart index 3f89df50ee..04a7f78e93 100644 --- a/pkgs/pub_semver/lib/src/version.dart +++ b/pkgs/pub_semver/lib/src/version.dart @@ -71,7 +71,7 @@ class Version implements VersionConstraint, VersionRange { /// string or a non-negative integer. It may also be empty, indicating that /// this version has no pre-release identifier. /// - /// The returned list is unmodifiable. + /// **Note:**The returned list shouldn't be modified. final List preRelease; /// The build identifier: "foo" in "1.2.3+foo". @@ -80,7 +80,7 @@ class Version implements VersionConstraint, VersionRange { /// string or a non-negative integer. It may also be empty, indicating that /// this version has no build identifier. /// - /// The returned list is unmodifiable. + /// **Note:** The returned list shouldn't be modified. final List build; /// The original string representation of the version number. @@ -101,9 +101,9 @@ class Version implements VersionConstraint, VersionRange { Version._(this.major, this.minor, this.patch, String? preRelease, String? build, this._text) : preRelease = preRelease == null || preRelease.isEmpty - ? const [] + ? [] : _splitParts(preRelease), - build = build == null || build.isEmpty ? const [] : _splitParts(build) { + build = build == null || build.isEmpty ? [] : _splitParts(build) { if (major < 0) throw ArgumentError('Major version must be non-negative.'); if (minor < 0) throw ArgumentError('Minor version must be non-negative.'); if (patch < 0) throw ArgumentError('Patch version must be non-negative.'); @@ -166,7 +166,7 @@ class Version implements VersionConstraint, VersionRange { // Return an integer part if possible, otherwise return the string // as-is int.tryParse(part) ?? part) - .toList(growable: false); + .toList(); @override bool operator ==(Object other) => diff --git a/pkgs/pub_semver/lib/src/version_constraint.dart b/pkgs/pub_semver/lib/src/version_constraint.dart index 948118ef3b..de17fb5a83 100644 --- a/pkgs/pub_semver/lib/src/version_constraint.dart +++ b/pkgs/pub_semver/lib/src/version_constraint.dart @@ -16,9 +16,15 @@ import 'version_union.dart'; /// version. abstract class VersionConstraint { /// A [VersionConstraint] that allows all versions. + /// + /// **Note:** This property shouldn't be reassigned. + /// It will be made `final` in a future release. static VersionConstraint any = VersionRange(); /// A [VersionConstraint] that allows no versions -- the empty set. + /// + /// **Note:** This property shouldn't be reassigned. + /// It will be made `final` in a future release. static VersionConstraint empty = const _EmptyVersion(); /// Parses a version constraint. diff --git a/pkgs/pub_semver/lib/src/version_union.dart b/pkgs/pub_semver/lib/src/version_union.dart index 844d3b8eff..24cca0a7e3 100644 --- a/pkgs/pub_semver/lib/src/version_union.dart +++ b/pkgs/pub_semver/lib/src/version_union.dart @@ -23,6 +23,8 @@ class VersionUnion implements VersionConstraint { /// * Its contents are disjoint and non-adjacent. In other words, for any two /// constraints next to each other in the list, there's some version between /// those constraints that they don't match. + /// + /// **Note:** The returned list shouldn't be modified. final List ranges; @override diff --git a/pkgs/pub_semver/pubspec.yaml b/pkgs/pub_semver/pubspec.yaml index 6d95e5754c..ac0aca7be0 100644 --- a/pkgs/pub_semver/pubspec.yaml +++ b/pkgs/pub_semver/pubspec.yaml @@ -1,5 +1,5 @@ name: pub_semver -version: 2.2.0-wip +version: 2.1.6 description: >- Versions and version constraints implementing pub's versioning policy. This is very similar to vanilla semver, with a few corner cases. From 6dee2e941432600f90e386d71ed2f0b7f37d29ab Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Wed, 26 Feb 2025 18:26:05 -0600 Subject: [PATCH 3/3] Fix spacing in doc comment note --- pkgs/pub_semver/lib/src/version.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/pub_semver/lib/src/version.dart b/pkgs/pub_semver/lib/src/version.dart index 04a7f78e93..732aea0bb5 100644 --- a/pkgs/pub_semver/lib/src/version.dart +++ b/pkgs/pub_semver/lib/src/version.dart @@ -71,7 +71,7 @@ class Version implements VersionConstraint, VersionRange { /// string or a non-negative integer. It may also be empty, indicating that /// this version has no pre-release identifier. /// - /// **Note:**The returned list shouldn't be modified. + /// **Note:** The returned list shouldn't be modified. final List preRelease; /// The build identifier: "foo" in "1.2.3+foo".