Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: sdk/lib/core/uri.dart

Issue 1406023018: Uri: use List.unmodifiable (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/uri.dart
diff --git a/sdk/lib/core/uri.dart b/sdk/lib/core/uri.dart
index 3abd352c1ae8e120a6934fe312c064132de29af1..d459a895e04e7bd88a5ceebe660e6cc50e464636 100644
--- a/sdk/lib/core/uri.dart
+++ b/sdk/lib/core/uri.dart
@@ -1009,26 +1009,27 @@ class Uri {
}
/**
- * Returns the URI path split into its segments. Each of the
- * segments in the returned list have been decoded. If the path is
- * empty the empty list will be returned. A leading slash `/` does
- * not affect the segments returned.
+ * Returns the URI path split into its segments. Each of the segments in the
+ * returned list have been decoded. If the path is empty the empty list will
+ * be returned. A leading slash `/` does not affect the segments returned.
*
* The returned list is unmodifiable and will throw [UnsupportedError] on any
* calls that would mutate it.
*/
List<String> get pathSegments {
- if (_pathSegments == null) {
- var pathToSplit = !path.isEmpty && path.codeUnitAt(0) == _SLASH
- ? path.substring(1)
- : path;
- _pathSegments = new UnmodifiableListView(
- pathToSplit == "" ? const<String>[]
- : pathToSplit.split("/")
- .map(Uri.decodeComponent)
- .toList(growable: false));
- }
- return _pathSegments;
+ var result = _pathSegments;
+ if (result != null) return result;
+
+ var pathToSplit = path;
+ if (pathToSplit.isNotEmpty && pathToSplit.codeUnitAt(0) == _SLASH) {
+ pathToSplit = pathToSplit.substring(1);
+ }
+ result = (pathToSplit == "")
+ ? const<String>[]
+ : new List<String>.unmodifiable(
+ pathToSplit.split("/").map(Uri.decodeComponent));
+ _pathSegments = result;
+ return result;
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698