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

Unified Diff: sdk/lib/_internal/pub/lib/src/io.dart

Issue 485893008: Cautionary tale about optimizing path manipulation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Comments. Created 6 years, 4 months 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
Index: sdk/lib/_internal/pub/lib/src/io.dart
diff --git a/sdk/lib/_internal/pub/lib/src/io.dart b/sdk/lib/_internal/pub/lib/src/io.dart
index ffbf30e71dcf45da820faa72b097839f38d69773..7f8c9ec088523d54586b963e7da172130c15ab0b 100644
--- a/sdk/lib/_internal/pub/lib/src/io.dart
+++ b/sdk/lib/_internal/pub/lib/src/io.dart
@@ -289,6 +289,16 @@ List<String> listDir(String dir, {bool recursive: false,
if (entity is Link) return false;
if (includeHidden) return true;
+ // Using substring here is generally problematic in cases where dir has one
+ // or more trailing slashes. If you do listDir("foo"), you'll get back
+ // paths like "foo/bar". If you do listDir("foo/"), you'll get "foo/bar"
+ // (note the trailing slash was dropped. If you do listDir("foo//"), you'll
+ // get "foo//bar".
+ //
+ // This means if you strip off the prefix, the resulting string may have a
+ // leading separator (if the prefix did not have a trailing one) or it may
+ // not. However, since we are only using the results of that to call
+ // contains() on, the leading separator is harmless.
assert(entity.path.startsWith(dir));
var pathInDir = entity.path.substring(dir.length);
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/barback/asset_environment.dart ('k') | sdk/lib/_internal/pub/lib/src/package.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698