Faster read; faster lookup; more tests; error on new package inside existing package root

Previously adding (reading a file consisting of) n non-overlapping
packages took O(n^2) time.
Looking up a single package in a structure with n non-overlapping
packages took O(n) time.

Here this is changed so the timings are more like O(n) and O(1),
respectively.

(all of these should be taken with a grain of salt as not only the
number of packages influence the time, but also the length of the paths
which I completely ignore here).

Run like this:
```
$ for i in 1 10 100 1000 5000 10000 50000; do dart test/bench.dart $i;
done
```

(With no warmup, only run once etc --- there's lots of variations
between runs, but for this purpose it doesn't really matter.)

Before:
Read file with 1 packages in 18 ms, looked up all packages in 0 ms
Read file with 10 packages in 22 ms, looked up all packages in 0 ms
Read file with 100 packages in 28 ms, looked up all packages in 1 ms
Read file with 1000 packages in 78 ms, looked up all packages in 14 ms
Read file with 5000 packages in 442 ms, looked up all packages in 384 ms
Read file with 10000 packages in 2254 ms, looked up all packages in 1826 ms
Read file with 50000 packages in 67572 ms, looked up all packages in 84050 ms

After:
Read file with 1 packages in 24 ms, looked up all packages in 0 ms
Read file with 10 packages in 23 ms, looked up all packages in 0 ms
Read file with 100 packages in 25 ms, looked up all packages in 1 ms
Read file with 1000 packages in 60 ms, looked up all packages in 6 ms
Read file with 5000 packages in 127 ms, looked up all packages in 10 ms
Read file with 10000 packages in 187 ms, looked up all packages in 13 ms
Read file with 50000 packages in 525 ms, looked up all packages in 61 ms

Furthermore:
* Previously no error was given if a package was inside the package root
  of another package. Now an error is given and tests are added.
* Previously at least one test didn't work because of a json syntax
  error. This has been fixed.
3 files changed
tree: 7628c2f3f4e21daf591bdb2bee8274418fe95b2e
  1. .github/
  2. example/
  3. lib/
  4. test/
  5. .gitignore
  6. analysis_options.yaml
  7. AUTHORS
  8. CHANGELOG.md
  9. CONTRIBUTING.md
  10. LICENSE
  11. pubspec.yaml
  12. README.md
README.md

Build Status pub package

Support for working with Package Configuration files as described in the Package Configuration v2 design document.

A Dart package configuration file is used to resolve Dart package names (e.g. foobar) to Dart files containing the source code for that package (e.g. file:///Users/myuser/.pub-cache/hosted/pub.dartlang.org/foobar-1.1.0). The standard package configuration file is .dart_tool/package_config.json, and is written by the Dart tool when the command dart pub get is run.

The primary libraries of this package are

  • package_config.dart: Defines the PackageConfig class and other types needed to use package configurations, and provides functions to find, read and write package configuration files.

  • package_config_types.dart: Just the PackageConfig class and other types needed to use package configurations. This library does not depend on dart:io.

The package includes deprecated backwards compatible functionality to work with the .packages file. This functionality will not be maintained, and will be removed in a future version of this package.