| Index: benchmark/after.dart.txt
|
| diff --git a/benchmark/benchmark.dart b/benchmark/after.dart.txt
|
| similarity index 86%
|
| copy from benchmark/benchmark.dart
|
| copy to benchmark/after.dart.txt
|
| index 3ab9d48272657fc864f93198592548a0c5b3364f..d1a2a929352872c8a181bcbcf2727d6bf9b83deb 100644
|
| --- a/benchmark/benchmark.dart
|
| +++ b/benchmark/after.dart.txt
|
| @@ -1,72 +1,3 @@
|
| -// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
| -// for details. All rights reserved. Use of this source code is governed by a
|
| -// BSD-style license that can be found in the LICENSE file.
|
| -
|
| -library dart_style.benchmark.benchmark;
|
| -
|
| -import 'dart:io';
|
| -
|
| -import 'package:dart_style/dart_style.dart';
|
| -
|
| -const NUM_TRIALS = 100;
|
| -const FORMATS_PER_TRIAL = 30;
|
| -
|
| -void main(List<String> args) {
|
| - var best = 99999999.0;
|
| -
|
| - // Run the benchmark several times. This ensures the VM is warmed up and lets
|
| - // us see how much variance there is.
|
| - for (var i = 0; i <= NUM_TRIALS; i++) {
|
| - var start = new DateTime.now();
|
| -
|
| - // For a single benchmark, format the source multiple times.
|
| - for (var j = 0; j < FORMATS_PER_TRIAL; j++) {
|
| - formatSource();
|
| - }
|
| -
|
| - var elapsed = new DateTime.now()
|
| - .difference(start).inMilliseconds / FORMATS_PER_TRIAL;
|
| -
|
| - // Keep track of the best run so far.
|
| - if (elapsed >= best) continue;
|
| - best = elapsed;
|
| -
|
| - // Don't print the first run. It's always terrible since the VM hasn't
|
| - // warmed up yet.
|
| - if (i == 0) continue;
|
| - printResult("Run ${padLeft('#$i', 3)}", elapsed);
|
| - }
|
| -
|
| - printResult("Best ", best);
|
| -}
|
| -
|
| -void printResult(String label, double time) {
|
| - print("$label: ${padLeft(time.toStringAsFixed(2), 4)}ms "
|
| - "${'=' * ((time * 5).toInt())}");
|
| -}
|
| -
|
| -String padLeft(input, int length) {
|
| - var result = input.toString();
|
| - if (result.length < length) {
|
| - result = " " * (length - result.length) + result;
|
| - }
|
| -
|
| - return result;
|
| -}
|
| -
|
| -void formatSource() {
|
| - var formatter = new DartFormatter();
|
| - var result = formatter.format(source);
|
| -
|
| - // Sanity check to make sure the output is what we expect and to make sure
|
| - // the VM doesn't optimize "dead" code away.
|
| - if (result.length != 29791) {
|
| - print("Incorrect output (length ${result.length}):\n$result");
|
| - exit(1);
|
| - }
|
| -}
|
| -
|
| -const source = r"""
|
| // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
| @@ -159,10 +90,12 @@ class BacktrackingSolver {
|
| }
|
|
|
| // A deeply nested statement that's hard on the formatter.
|
| - isTwoWay = !isEvent && bindings.isWhole && (isCustomTag ||
|
| - tag == 'input' && (name == 'value' || name =='checked') ||
|
| - tag == 'select' && (name == 'selectedindex' || name == 'value') ||
|
| - tag == 'textarea' && name == 'value');
|
| + isTwoWay = !isEvent &&
|
| + bindings.isWhole &&
|
| + (isCustomTag ||
|
| + tag == 'input' && (name == 'value' || name == 'checked') ||
|
| + tag == 'select' && (name == 'selectedindex' || name == 'value') ||
|
| + tag == 'textarea' && name == 'value');
|
| }
|
|
|
| /// Run the solver.
|
| @@ -187,31 +120,18 @@ class BacktrackingSolver {
|
| _validateSdkConstraint(root.pubspec);
|
| return _traverseSolution();
|
| }).then((packages) {
|
| - var pubspecs = new Map.fromIterable(
|
| - packages,
|
| - key: (id) => id.name,
|
| - value: (id) => cache.getCachedPubspec(id));
|
| -
|
| - return new SolveResult.success(
|
| - sources,
|
| - root,
|
| - lockFile,
|
| - packages,
|
| - overrides,
|
| - pubspecs,
|
| - _getAvailableVersions(packages),
|
| + var pubspecs = new Map.fromIterable(packages,
|
| + key: (id) => id.name, value: (id) => cache.getCachedPubspec(id));
|
| +
|
| + return new SolveResult.success(sources, root, lockFile, packages,
|
| + overrides, pubspecs, _getAvailableVersions(packages),
|
| attemptedSolutions);
|
| }).catchError((error) {
|
| if (error is! SolveFailure) throw error;
|
|
|
| // Wrap a failure in a result so we can attach some other data.
|
| return new SolveResult.failure(
|
| - sources,
|
| - root,
|
| - lockFile,
|
| - overrides,
|
| - error,
|
| - attemptedSolutions);
|
| + sources, root, lockFile, overrides, error, attemptedSolutions);
|
| }).whenComplete(() {
|
| // Gather some solving metrics.
|
| var buffer = new StringBuffer();
|
| @@ -578,8 +498,7 @@ class Traverser {
|
| for (var dep in deps) {
|
| if (!dep.isRoot && _solver.sources[dep.source] is UnknownSource) {
|
| throw new UnknownSourceException(
|
| - id.name,
|
| - [new Dependency(id.name, id.version, dep)]);
|
| + id.name, [new Dependency(id.name, id.version, dep)]);
|
| }
|
| }
|
|
|
| @@ -598,8 +517,8 @@ class Traverser {
|
| /// Desctructively modifies [deps]. Completes to a list of packages if the
|
| /// traversal is complete. Completes it to an error if a failure occurred.
|
| /// Otherwise, recurses.
|
| - Future<List<PackageId>> _traverseDeps(PackageId depender,
|
| - DependencyQueue deps) {
|
| + Future<List<PackageId>> _traverseDeps(
|
| + PackageId depender, DependencyQueue deps) {
|
| // Move onto the next package if we've traversed all of these references.
|
| if (deps.isEmpty) return _traversePackage();
|
|
|
| @@ -627,8 +546,9 @@ class Traverser {
|
|
|
| // See if it's possible for a package to match that constraint.
|
| if (constraint.isEmpty) {
|
| - var constraints = dependencies.map(
|
| - (dep) => " ${dep.dep.constraint} from ${dep.depender}").join('\n');
|
| + var constraints = dependencies
|
| + .map((dep) => " ${dep.dep.constraint} from ${dep.depender}")
|
| + .join('\n');
|
| _solver.logSolve('disjoint constraints on ${dep.name}:\n$constraints');
|
| throw new DisjointConstraintException(dep.name, dependencies);
|
| }
|
| @@ -661,10 +581,7 @@ class Traverser {
|
| if (allowed.isEmpty) {
|
| _solver.logSolve('no versions for ${dep.name} match $constraint');
|
| throw new NoVersionException(
|
| - dep.name,
|
| - null,
|
| - constraint,
|
| - _getDependencies(dep.name));
|
| + dep.name, null, constraint, _getDependencies(dep.name));
|
| }
|
|
|
| // If we're doing an upgrade on this package, only allow the latest
|
| @@ -682,9 +599,7 @@ class Traverser {
|
| if (error is PackageNotFoundException) {
|
| // Show the user why the package was being requested.
|
| throw new DependencyNotFoundException(
|
| - dep.name,
|
| - error,
|
| - _getDependencies(dep.name));
|
| + dep.name, error, _getDependencies(dep.name));
|
| }
|
|
|
| throw error;
|
| @@ -713,9 +628,8 @@ class Traverser {
|
| // Make sure all of the existing descriptions match the new reference.
|
| var source = _solver.sources[dep.source];
|
| if (!source.descriptionsEqual(dep.description, required.dep.description)) {
|
| - _solver.logSolve(
|
| - 'description mismatch on ${dep.name}: '
|
| - '${required.dep.description} != ${dep.description}');
|
| + _solver.logSolve('description mismatch on ${dep.name}: '
|
| + '${required.dep.description} != ${dep.description}');
|
| throw new DescriptionMismatchException(dep.name, [required, dependency]);
|
| }
|
| }
|
| @@ -734,10 +648,7 @@ class Traverser {
|
| if (!dep.constraint.allows(selected.version)) {
|
| _solver.logSolve('selection $selected does not match $constraint');
|
| throw new NoVersionException(
|
| - dep.name,
|
| - selected.version,
|
| - constraint,
|
| - _getDependencies(dep.name));
|
| + dep.name, selected.version, constraint, _getDependencies(dep.name));
|
| }
|
|
|
| return selected;
|
| @@ -753,17 +664,17 @@ class Traverser {
|
|
|
| return Future.wait(barback.pubConstraints.keys.map((depName) {
|
| var constraint = barback.pubConstraints[depName];
|
| - _solver.logSolve(
|
| - 'add implicit $constraint pub dependency on ' '$depName');
|
| + _solver
|
| + .logSolve('add implicit $constraint pub dependency on ' '$depName');
|
|
|
| var override = _solver._overrides[depName];
|
|
|
| // Use the same source and description as the dependency override if one
|
| // exists. This is mainly used by the pkgbuild tests, which use dependency
|
| // overrides for all repo packages.
|
| - var pubDep = override == null ?
|
| - new PackageDep(depName, "hosted", constraint, depName) :
|
| - override.withConstraint(constraint);
|
| + var pubDep = override == null
|
| + ? new PackageDep(depName, "hosted", constraint, depName)
|
| + : override.withConstraint(constraint);
|
| return _registerDependency(
|
| new Dependency("pub itself", Version.none, pubDep));
|
| }));
|
| @@ -789,17 +700,16 @@ class Traverser {
|
| /// can have a bunch of dependencies back onto the root package as long as
|
| /// they all agree with each other.
|
| Dependency _getRequired(String name) {
|
| - return _getDependencies(
|
| - name).firstWhere((dep) => !dep.dep.isRoot, orElse: () => null);
|
| + return _getDependencies(name).firstWhere((dep) => !dep.dep.isRoot,
|
| + orElse: () => null);
|
| }
|
|
|
| /// Gets the combined [VersionConstraint] currently being placed on package
|
| /// [name].
|
| VersionConstraint _getConstraint(String name) {
|
| - var constraint = _getDependencies(
|
| - name).map(
|
| - (dep) =>
|
| - dep.dep.constraint).fold(VersionConstraint.any, (a, b) => a.intersect(b));
|
| + var constraint = _getDependencies(name)
|
| + .map((dep) => dep.dep.constraint)
|
| + .fold(VersionConstraint.any, (a, b) => a.intersect(b));
|
|
|
| return constraint;
|
| }
|
| @@ -827,8 +737,7 @@ class Traverser {
|
|
|
| var source = _solver.sources[package.source];
|
| if (!source.descriptionsEqual(
|
| - package.description,
|
| - required.dep.description)) return null;
|
| + package.description, required.dep.description)) return null;
|
| }
|
|
|
| return package;
|
| @@ -850,21 +759,20 @@ class Traverser {
|
| // to report compile errors to the user in an easily visible way. Need to
|
| // make sure paths in errors are mapped to the original source path so they
|
| // can understand them.
|
| - return dart.compile(
|
| - entrypoint, provider,
|
| + return dart.compile(entrypoint, provider,
|
| commandLineOptions: _configCommandLineOptions,
|
| csp: _configBool('csp'),
|
| checked: _configBool('checked'),
|
| - minify: _configBool(
|
| - 'minify', defaultsTo: _settings.mode == BarbackMode.RELEASE),
|
| + minify: _configBool('minify',
|
| + defaultsTo: _settings.mode == BarbackMode.RELEASE),
|
| verbose: _configBool('verbose'),
|
| environment: _configEnvironment,
|
| packageRoot: _environment.rootPackage.path("packages"),
|
| analyzeAll: _configBool('analyzeAll'),
|
| suppressWarnings: _configBool('suppressWarnings'),
|
| suppressHints: _configBool('suppressHints'),
|
| - suppressPackageWarnings: _configBool(
|
| - 'suppressPackageWarnings', defaultsTo: true),
|
| + suppressPackageWarnings: _configBool('suppressPackageWarnings',
|
| + defaultsTo: true),
|
| terse: _configBool('terse'),
|
| includeSourceMapUrls: _settings.mode != BarbackMode.RELEASE);
|
| }
|
| @@ -877,9 +785,7 @@ class Traverser {
|
| void _validateSdkConstraint(Pubspec pubspec) {
|
| if (pubspec.environment.sdkVersion.allows(sdk.version)) return;
|
|
|
| - throw new BadSdkVersionException(
|
| - pubspec.name,
|
| + throw new BadSdkVersionException(pubspec.name,
|
| 'Package ${pubspec.name} requires SDK version '
|
| - '${pubspec.environment.sdkVersion} but the current SDK is ' '${sdk.version}.');
|
| + '${pubspec.environment.sdkVersion} but the current SDK is ' '${sdk.version}.');
|
| }
|
| -""";
|
|
|