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

Side by Side Diff: pkg/path/lib/src/context.dart

Issue 429173002: Don't cache path Context based on cwd, as cwd involves a system-call to compute. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library path.context; 5 library path.context;
6 6
7 import 'internal_style.dart'; 7 import 'internal_style.dart';
8 import 'style.dart'; 8 import 'style.dart';
9 import 'parsed_path.dart'; 9 import 'parsed_path.dart';
10 import 'path_exception.dart'; 10 import 'path_exception.dart';
11 import '../path.dart' as p; 11 import '../path.dart' as p;
12 12
13 /// An instantiable class for manipulating paths. Unlike the top-level 13 /// An instantiable class for manipulating paths. Unlike the top-level
14 /// functions, this lets you explicitly select what platform the paths will use. 14 /// functions, this lets you explicitly select what platform the paths will use.
15 class Context { 15 class Context {
16 /// Creates a new path context for the given style and current directory. 16 /// Creates a new path context for the given style and current directory.
17 /// 17 ///
18 /// If [style] is omitted, it uses the host operating system's path style. If 18 /// If [style] is omitted, it uses the host operating system's path style. If
19 /// only [current] is omitted, it defaults ".". If *both* [style] and 19 /// only [current] is omitted, it defaults ".". If *both* [style] and
20 /// [current] are omitted, [current] defaults to the real current working 20 /// [current] are omitted, [current] defaults to the real current working
21 /// directory. 21 /// directory.
22 /// 22 ///
23 /// On the browser, [style] defaults to [Style.url] and [current] defaults to 23 /// On the browser, [style] defaults to [Style.url] and [current] defaults to
24 /// the current URL. 24 /// the current URL.
25 factory Context({Style style, String current}) { 25 factory Context({Style style, String current}) {
26 if (current == null) { 26 if (current == null && style != null) {
27 if (style == null) { 27 current = ".";
28 current = p.current;
29 } else {
30 current = ".";
31 }
32 } 28 }
33 29
34 if (style == null) { 30 if (style == null) {
35 style = Style.platform; 31 style = Style.platform;
36 } else if (style is! InternalStyle) { 32 } else if (style is! InternalStyle) {
37 throw new ArgumentError("Only styles defined by the path package are " 33 throw new ArgumentError("Only styles defined by the path package are "
38 "allowed."); 34 "allowed.");
39 } 35 }
40 36
41 return new Context._(style, current); 37 return new Context._(style, current);
42 } 38 }
43 39
44 Context._(this.style, this.current); 40 Context._(this.style, this._current);
45 41
46 /// The style of path that this context works with. 42 /// The style of path that this context works with.
47 final InternalStyle style; 43 final InternalStyle style;
48 44
45 /// The current given when Context was created. If null, current should be
Bob Nystrom 2014/07/30 16:15:08 "current" -> "current directory". "should be" ->
Anders Johnsen 2014/07/31 06:19:42 Done.
46 /// evaluated from 'p.current'.
47 final String _current;
48
49 /// The current directory that relative paths will be relative to. 49 /// The current directory that relative paths will be relative to.
Bob Nystrom 2014/07/30 16:15:08 "will be" -> "are".
Anders Johnsen 2014/07/31 06:19:42 Done.
50 final String current; 50 String get current => _current != null ? _current : p.current;
51 51
52 /// Gets the path separator for the context's [style]. On Mac and Linux, 52 /// Gets the path separator for the context's [style]. On Mac and Linux,
53 /// this is `/`. On Windows, it's `\`. 53 /// this is `/`. On Windows, it's `\`.
54 String get separator => style.separator; 54 String get separator => style.separator;
55 55
56 /// Creates a new path by appending the given path parts to [current]. 56 /// Creates a new path by appending the given path parts to [current].
57 /// Equivalent to [join()] with [current] as the first argument. Example: 57 /// Equivalent to [join()] with [current] as the first argument. Example:
58 /// 58 ///
59 /// var context = new Context(current: '/root'); 59 /// var context = new Context(current: '/root');
60 /// context.absolute('path', 'to', 'foo'); // -> '/root/path/to/foo' 60 /// context.absolute('path', 'to', 'foo'); // -> '/root/path/to/foo'
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 // Show the arguments. 538 // Show the arguments.
539 var message = new StringBuffer(); 539 var message = new StringBuffer();
540 message.write("$method("); 540 message.write("$method(");
541 message.write(args.take(numArgs) 541 message.write(args.take(numArgs)
542 .map((arg) => arg == null ? "null" : '"$arg"') 542 .map((arg) => arg == null ? "null" : '"$arg"')
543 .join(", ")); 543 .join(", "));
544 message.write("): part ${i - 1} was null, but part $i was not."); 544 message.write("): part ${i - 1} was null, but part $i was not.");
545 throw new ArgumentError(message.toString()); 545 throw new ArgumentError(message.toString());
546 } 546 }
547 } 547 }
OLDNEW
« no previous file with comments | « pkg/path/lib/path.dart ('k') | pkg/path/pubspec.yaml » ('j') | pkg/path/pubspec.yaml » ('J')

Powered by Google App Engine
This is Rietveld 408576698