Don't cache path Context based on cwd, as cwd involves a system-call to compute.
Instead, delay evaluation of cwd to the actual use of it.
BUG=
R=rnystrom@google.com
Review URL: https://codereview.chromium.org//429173002
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/path@38844 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5331635..9b5520b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.2.3
+
+* Don't cache path Context based on cwd, as cwd involves a system-call to
+ compute.
+
## 1.2.2
* Remove the documentation link from the pubspec so this is linked to
diff --git a/lib/path.dart b/lib/path.dart
index 599a351..b9a4175 100644
--- a/lib/path.dart
+++ b/lib/path.dart
@@ -49,7 +49,7 @@
import 'src/context.dart';
import 'src/style.dart';
-export 'src/context.dart';
+export 'src/context.dart' hide createInternal;
export 'src/path_exception.dart';
export 'src/style.dart';
@@ -62,22 +62,9 @@
/// A default context for manipulating URLs.
final url = new Context(style: Style.url);
-/// The result of [Uri.base] last time the current working directory was
-/// calculated.
-///
-/// This is used to invalidate [_cachedContext] when the working directory has
-/// changed since the last time a function was called.
-Uri _lastBaseUri;
-
/// An internal context for the current OS so we can provide a straight
/// functional interface and not require users to create one.
-Context get _context {
- if (_cachedContext != null && Uri.base == _lastBaseUri) return _cachedContext;
- _lastBaseUri = Uri.base;
- _cachedContext = new Context();
- return _cachedContext;
-}
-Context _cachedContext;
+final Context _context = createInternal();
/// Returns the [Style] of the current context.
///
diff --git a/lib/src/context.dart b/lib/src/context.dart
index 823e0c2..8901049 100644
--- a/lib/src/context.dart
+++ b/lib/src/context.dart
@@ -10,6 +10,8 @@
import 'path_exception.dart';
import '../path.dart' as p;
+Context createInternal() => new Context._internal();
+
/// An instantiable class for manipulating paths. Unlike the top-level
/// functions, this lets you explicitly select what platform the paths will use.
class Context {
@@ -41,13 +43,20 @@
return new Context._(style, current);
}
- Context._(this.style, this.current);
+ /// Create a [Context] to be used internally within path.
+ Context._internal() : style = Style.platform;
+
+ Context._(this.style, this._current);
/// The style of path that this context works with.
final InternalStyle style;
- /// The current directory that relative paths will be relative to.
- final String current;
+ /// The current directory given when Context was created. If null, current
+ /// directory is evaluated from 'p.current'.
+ final String _current;
+
+ /// The current directory that relative paths are relative to.
+ String get current => _current != null ? _current : p.current;
/// Gets the path separator for the context's [style]. On Mac and Linux,
/// this is `/`. On Windows, it's `\`.
diff --git a/pubspec.yaml b/pubspec.yaml
index e9948de..da69c0e 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: path
-version: 1.2.2
+version: 1.2.3
author: Dart Team <misc@dartlang.org>
description: >
A string-based path manipulation library. All of the path operations you know