bug 1298422 - vendor byteorder into third-party/rust. r=froydnj

MozReview-Commit-ID: ChKCKiIVEfq

--HG--
extra : rebase_source : c0da7411a2f0b7fc171c9ebb99fce91361944aa5
This commit is contained in:
Ted Mielczarek 2016-09-08 15:12:34 -07:00
parent 919372cf5c
commit e254cc07b8
49 changed files with 309 additions and 516 deletions

6
.cargo/config.in Normal file
View File

@ -0,0 +1,6 @@
[source.crates-io]
registry = 'https://github.com/rust-lang/crates.io-index'
replace-with = 'vendored-sources'
[source.vendored-sources]
directory = '@top_srcdir@/third_party/rust'

View File

@ -92,6 +92,10 @@ case $cmd in
# copy build and config directory.
cp -pPR ${TOPSRCDIR}/build ${TOPSRCDIR}/config ${tgtpath}
# copy cargo config
${MKDIR} -p ${tgtpath}/.cargo
cp -pPR ${TOPSRCDIR}/.cargo/config.in ${tgtpath}/.cargo
# put in js itself
cp -pPR ${TOPSRCDIR}/mfbt ${tgtpath}
cp -p ${SRCDIR}/../moz.configure ${tgtpath}/js

View File

@ -18,7 +18,7 @@ exclude = [
]
[dependencies]
byteorder = { version = "0.5.0", path = "../byteorder" }
byteorder = "0.5.0"
[dev-dependencies]
test-assembler = "0.1.2"

View File

@ -84,4 +84,6 @@ if not CONFIG['JS_STANDALONE'] and CONFIG['MOZ_BUILD_APP']:
# Bring in the configuration for the configured application.
include('/' + CONFIG['MOZ_BUILD_APP'] + '/app.mozbuild')
CONFIGURE_SUBST_FILES += ['.cargo/config']
include('build/templates.mozbuild')

View File

@ -408,55 +408,6 @@ class TreeMetadataEmitter(LoggingMixin):
'%s %s of crate %s refers to a non-existent path' % (description, dep_crate_name, crate_name),
context)
def _verify_local_paths(self, context, crate_dir, config):
"""Verify that a Cargo.toml config specifies local paths for all its dependencies."""
crate_name = config['package']['name']
# This is not exactly how cargo works (cargo would permit
# identically-named packages with different versions in the same
# library), but we want to try and avoid using multiple
# different versions of a single package for code size reasons.
if crate_name not in self._crate_directories:
self._crate_directories[crate_name] = crate_dir
else:
previous_dir = self._crate_directories[crate_name]
if crate_dir != previous_dir:
raise SandboxValidationError(
'Crate %s found at multiple paths: %s, %s' % (crate_name, crate_dir, previous_dir),
context)
# This check should ideally be positioned when we're recursing through
# dependencies, but then we would never get the chance to run the
# duplicated names check above.
if crate_name in self._crate_verified_local:
return
crate_deps = config.get('dependencies', {})
if crate_deps:
self._verify_deps(context, crate_dir, crate_name, crate_deps)
has_custom_build = 'build' in config['package']
build_deps = config.get('build-dependencies', {})
if has_custom_build and build_deps:
self._verify_deps(context, crate_dir, crate_name, build_deps,
description='Build dependency')
# We have now verified that all the declared dependencies of
# this crate have local paths. Now verify recursively.
self._crate_verified_local.add(crate_name)
if crate_deps:
for dep_crate_name, values in crate_deps.iteritems():
rel_dep_dir = mozpath.normpath(mozpath.join(crate_dir, values['path']))
dep_toml = mozpath.join(context.config.topsrcdir, rel_dep_dir, 'Cargo.toml')
self._verify_local_paths(context, rel_dep_dir, self._parse_cargo_file(dep_toml))
if has_custom_build and build_deps:
for dep_crate_name, values in build_deps.iteritems():
rel_dep_dir = mozpath.normpath(mozpath.join(crate_dir, values['path']))
dep_toml = mozpath.join(context.config.topsrcdir, rel_dep_dir, 'Cargo.toml')
self._verify_local_paths(context, rel_dep_dir, self._parse_cargo_file(dep_toml))
def _rust_library(self, context, libname, static_args):
# We need to note any Rust library for linking purposes.
cargo_file = mozpath.join(context.srcdir, 'Cargo.toml')
@ -490,7 +441,6 @@ class TreeMetadataEmitter(LoggingMixin):
'crate-type %s is not permitted for %s' % (crate_type, libname),
context)
self._verify_local_paths(context, context.relsrcdir, config)
return RustLibrary(context, libname, cargo_file, crate_type, **static_args)

View File

@ -1,14 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
build = "build.rs"
[lib]
crate-type = ["staticlib"]
[build-dependencies]
bogus = { version = "0.1.0", path = "/path/to/somewhere" }

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,14 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
build = "build.rs"
[lib]
crate-type = ["staticlib"]
[build-dependencies]
bogus = { version = "0.1.0", path = "../bogus" }

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,12 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[lib]
crate-type = ["staticlib"]
[dependencies]
ok = { version = "0.1.0", path = "ok" }

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,11 +0,0 @@
[package]
name = "ok"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
build = "build.rs"
[build-dependencies]
bogus = { version = "0.1.0" }

View File

@ -1,14 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
build = "build.rs"
[lib]
crate-type = ["staticlib"]
[build-dependencies]
bogus = "0.1.0"

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,14 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
build = "build.rs"
[lib]
crate-type = ["staticlib"]
[build-dependencies]
bogus = { version = "0.1.0" }

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,12 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[lib]
crate-type = ["staticlib"]
[dependencies]
bogus = { version = "0.1.0", path = "/path/to/somewhere" }

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,12 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[lib]
crate-type = ["staticlib"]
[dependencies]
bogus = { version = "0.1.0", path = "../bogus" }

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,12 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[lib]
crate-type = ["staticlib"]
[dependencies]
ok = { version = "0.1.0", path = "ok" }

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,9 +0,0 @@
[package]
name = "ok"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[dependencies]
bogus = { version = "0.1.0" }

View File

@ -1,12 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[lib]
crate-type = ["staticlib"]
[dependencies]
bogus = "0.1.0"

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,12 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[lib]
crate-type = ["staticlib"]
[dependencies]
bogus = { version = "0.1.0" }

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -1,13 +0,0 @@
[package]
name = "random-crate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[lib]
crate-type = ["staticlib"]
[dependencies]
crate-one = { path = "crate-one" }
crate-two = { path = "crate-two" }

View File

@ -1,9 +0,0 @@
[package]
name = "crate-one"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[dependencies]
duplicate = { path = "duplicate" }

View File

@ -1,6 +0,0 @@
[package]
name = "duplicate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]

View File

@ -1,9 +0,0 @@
[package]
name = "crate-two"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]
[dependencies]
duplicate = { path = "duplicate" }

View File

@ -1,6 +0,0 @@
[package]
name = "duplicate"
version = "0.1.0"
authors = [
"Nobody <nobody@mozilla.org>",
]

View File

@ -1,18 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
@template
def Library(name):
'''Template for libraries.'''
LIBRARY_NAME = name
@template
def RustLibrary(name):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
RustLibrary('random-crate')

View File

@ -993,74 +993,6 @@ class TestEmitterBasic(unittest.TestCase):
'Only source directory paths allowed in FINAL_TARGET_PP_FILES:'):
self.read_topsrcdir(reader)
def test_crate_dependency_version_only(self):
'''Test that including a crate with a version-only dependency fails.'''
reader = self.reader('crate-dependency-version-only')
with self.assertRaisesRegexp(SandboxValidationError,
'Dependency.*of crate.*does not list a path'):
self.read_topsrcdir(reader)
def test_crate_dependency_with_dict(self):
'''Test that including a crate with a dict-using version-only dependency fails.'''
reader = self.reader('crate-dependency-with-dict')
with self.assertRaisesRegexp(SandboxValidationError,
'Dependency.*of crate.*does not list a path'):
self.read_topsrcdir(reader)
def test_crate_dependency_absolute_path(self):
'''Test that including a crate with an absolute-path dependency fails.'''
reader = self.reader('crate-dependency-absolute-path')
with self.assertRaisesRegexp(SandboxValidationError,
'Dependency.*of crate.*has a non-relative path'):
self.read_topsrcdir(reader)
def test_crate_dependency_nonexistent_path(self):
'''Test that including a crate with a non-existent dependency fails.'''
reader = self.reader('crate-dependency-nonexistent-path')
with self.assertRaisesRegexp(SandboxValidationError,
'Dependency.*of crate.*refers to a non-existent path'):
self.read_topsrcdir(reader)
def test_crate_build_dependency_version_only(self):
'''Test that including a crate with a version-only dependency fails.'''
reader = self.reader('crate-build-dependency-version-only')
with self.assertRaisesRegexp(SandboxValidationError,
'Build dependency.*of crate.*does not list a path'):
self.read_topsrcdir(reader)
def test_crate_build_dependency_with_dict(self):
'''Test that including a crate with a dict-using version-only dependency fails.'''
reader = self.reader('crate-build-dependency-with-dict')
with self.assertRaisesRegexp(SandboxValidationError,
'Build dependency.*of crate.*does not list a path'):
self.read_topsrcdir(reader)
def test_crate_build_dependency_absolute_path(self):
'''Test that including a crate with an absolute-path dependency fails.'''
reader = self.reader('crate-build-dependency-absolute-path')
with self.assertRaisesRegexp(SandboxValidationError,
'Build dependency.*of crate.*has a non-relative path'):
self.read_topsrcdir(reader)
def test_crate_build_dependency_nonexistent_path(self):
'''Test that including a crate with a non-existent dependency fails.'''
reader = self.reader('crate-build-dependency-nonexistent-path')
with self.assertRaisesRegexp(SandboxValidationError,
'Build dependency.*of crate.*refers to a non-existent path'):
self.read_topsrcdir(reader)
def test_crate_dependency_recursive(self):
reader = self.reader('crate-dependency-recursive')
with self.assertRaisesRegexp(SandboxValidationError,
'Dependency.*of crate.*does not list a path'):
self.read_topsrcdir(reader)
def test_crate_build_dependency_recursive(self):
reader = self.reader('crate-build-dependency-recursive')
with self.assertRaisesRegexp(SandboxValidationError,
'Build dependency.*of crate.*does not list a path'):
self.read_topsrcdir(reader)
def test_rust_library_no_cargo_toml(self):
'''Test that defining a RustLibrary without a Cargo.toml fails.'''
reader = self.reader('rust-library-no-cargo-toml')
@ -1111,13 +1043,6 @@ class TestEmitterBasic(unittest.TestCase):
self.assertEqual(len(objs), 1)
self.assertIsInstance(objs[0], RustLibrary)
def test_duplicate_crate_names(self):
'''Test that crates are not duplicated in the tree.'''
reader = self.reader('duplicated-crate-names')
with self.assertRaisesRegexp(SandboxValidationError,
'Crate.*found at multiple paths'):
self.read_topsrcdir(reader)
def test_android_res_dirs(self):
"""Test that ANDROID_RES_DIRS works properly."""
reader = self.reader('android-res-dirs')

View File

@ -0,0 +1 @@
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".gitignore":"2879af3c0512f976015d532e2d768f04ff22fdcf8745b69b955b78fda321c3fb",".travis.yml":"81545ce3c6c72111a68434464c3f9fa8df9cbe39759a081fac527628ab21ae0c","COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"a7282931b50dff2e463f82baaed95a9d76636bc0fef3e921acd8ca69eab32b83","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","Makefile":"a45a128685a2ae7d4fa39d310786674417ee113055ef290a11f88002285865fc","README.md":"fbcc46b6d0a585096737f50922818b59016b69d959b05f1b29863b2af8e4da43","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","benches/bench.rs":"f583692d829c8dfe19b1d5b9e968ccf5c74d6733367ca183edff74041a6afedd","session.vim":"95cb1d7caf0ff7fbe76ec911988d908ddd883381c925ba64b537695bc9f021c4","src/lib.rs":"ef9e7a218fa3a4912c47f6840d32b975940d98277b6c9be85e8d7d045552eb87","src/new.rs":"161c21b7ebb5668c7cc70b46b0eb37709e06bb9c854f2fdfc6ce3d3babcbf3de"},"package":"0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"}

0
third_party/rust/byteorder/.cargo-ok vendored Normal file
View File

6
third_party/rust/byteorder/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.*.swp
doc
tags
build
target
Cargo.lock

15
third_party/rust/byteorder/.travis.yml vendored Normal file
View File

@ -0,0 +1,15 @@
language: rust
matrix:
include:
- rust: "nightly"
env: TEST_SUITE=suite_nightly
- rust: "beta"
env: TEST_SUITE=suite_beta
- rust: "stable"
env: TEST_SUITE=suite_stable
script:
- cargo build --verbose
- cargo test --verbose
- if [ "$TEST_SUITE" = "suite_nightly" ]; then
cargo bench --verbose;
fi

3
third_party/rust/byteorder/COPYING vendored Normal file
View File

@ -0,0 +1,3 @@
This project is dual-licensed under the Unlicense and MIT licenses.
You may use this code under the terms of either license.

21
third_party/rust/byteorder/LICENSE-MIT vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Andrew Gallant
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

14
third_party/rust/byteorder/Makefile vendored Normal file
View File

@ -0,0 +1,14 @@
all:
echo Nothing to do...
ctags:
ctags --recurse --options=ctags.rust --languages=Rust
docs:
cargo doc
in-dir ./target/doc fix-perms
rscp ./target/doc/* gopher:~/www/burntsushi.net/rustdoc/
push:
git push origin master
git push github master

59
third_party/rust/byteorder/README.md vendored Normal file
View File

@ -0,0 +1,59 @@
This crate provides convenience methods for encoding and decoding numbers in
either big-endian or little-endian order. This is meant to replace the old
methods defined on the standard library `Reader` and `Writer` traits.
[![Build status](https://api.travis-ci.org/BurntSushi/byteorder.png)](https://travis-ci.org/BurntSushi/byteorder)
[![](http://meritbadge.herokuapp.com/byteorder)](https://crates.io/crates/byteorder)
Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
### Documentation
[http://burntsushi.net/rustdoc/byteorder/](http://burntsushi.net/rustdoc/byteorder/).
The documentation includes examples.
### Installation
This crate works with Cargo and is on
[crates.io](https://crates.io/crates/byteorder). The package is regularly
updated. Add it to your `Cargo.toml` like so:
```toml
[dependencies]
byteorder = "0.5"
```
If you want to augment existing `Read` and `Write` traits, then import the
extension methods like so:
```rust
extern crate byteorder;
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian, LittleEndian};
```
For example:
```rust
use std::io::Cursor;
use byteorder::{BigEndian, ReadBytesExt};
let mut rdr = Cursor::new(vec![2, 5, 3, 0]);
// Note that we use type parameters to indicate which kind of byte order
// we want!
assert_eq!(517, rdr.read_u16::<BigEndian>().unwrap());
assert_eq!(768, rdr.read_u16::<BigEndian>().unwrap());
```
### `no_std` crates
This crate has a feature, `std`, that is enabled by default. To use this crate
in a `no_std` context, add the following to your `Cargo.toml`:
```toml
[dependencies]
byteorder = { version = "0.5", default-features = false }
```

24
third_party/rust/byteorder/UNLICENSE vendored Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>

View File

@ -0,0 +1,148 @@
#![feature(test)]
extern crate byteorder;
extern crate test;
macro_rules! bench_num {
($name:ident, $read:ident, $bytes:expr, $data:expr) => (
mod $name {
use byteorder::{ByteOrder, BigEndian, NativeEndian, LittleEndian};
use super::test::Bencher;
use super::test::black_box as bb;
const NITER: usize = 100_000;
#[bench]
fn read_big_endian(b: &mut Bencher) {
let buf = $data;
b.iter(|| {
for _ in 0..NITER {
bb(BigEndian::$read(&buf, $bytes));
}
});
}
#[bench]
fn read_little_endian(b: &mut Bencher) {
let buf = $data;
b.iter(|| {
for _ in 0..NITER {
bb(LittleEndian::$read(&buf, $bytes));
}
});
}
#[bench]
fn read_native_endian(b: &mut Bencher) {
let buf = $data;
b.iter(|| {
for _ in 0..NITER {
bb(NativeEndian::$read(&buf, $bytes));
}
});
}
}
);
($ty:ident, $max:ident,
$read:ident, $write:ident, $size:expr, $data:expr) => (
mod $ty {
use std::$ty;
use byteorder::{ByteOrder, BigEndian, NativeEndian, LittleEndian};
use super::test::Bencher;
use super::test::black_box as bb;
const NITER: usize = 100_000;
#[bench]
fn read_big_endian(b: &mut Bencher) {
let buf = $data;
b.iter(|| {
for _ in 0..NITER {
bb(BigEndian::$read(&buf));
}
});
}
#[bench]
fn read_little_endian(b: &mut Bencher) {
let buf = $data;
b.iter(|| {
for _ in 0..NITER {
bb(LittleEndian::$read(&buf));
}
});
}
#[bench]
fn read_native_endian(b: &mut Bencher) {
let buf = $data;
b.iter(|| {
for _ in 0..NITER {
bb(NativeEndian::$read(&buf));
}
});
}
#[bench]
fn write_big_endian(b: &mut Bencher) {
let mut buf = $data;
let n = $ty::$max;
b.iter(|| {
for _ in 0..NITER {
bb(BigEndian::$write(&mut buf, n));
}
});
}
#[bench]
fn write_little_endian(b: &mut Bencher) {
let mut buf = $data;
let n = $ty::$max;
b.iter(|| {
for _ in 0..NITER {
bb(LittleEndian::$write(&mut buf, n));
}
});
}
#[bench]
fn write_native_endian(b: &mut Bencher) {
let mut buf = $data;
let n = $ty::$max;
b.iter(|| {
for _ in 0..NITER {
bb(NativeEndian::$write(&mut buf, n));
}
});
}
}
);
}
bench_num!(u16, MAX, read_u16, write_u16, 2, [1, 2]);
bench_num!(i16, MAX, read_i16, write_i16, 2, [1, 2]);
bench_num!(u32, MAX, read_u32, write_u32, 4, [1, 2, 3, 4]);
bench_num!(i32, MAX, read_i32, write_i32, 4, [1, 2, 3, 4]);
bench_num!(u64, MAX, read_u64, write_u64, 8, [1, 2, 3, 4, 5, 6, 7, 8]);
bench_num!(i64, MAX, read_i64, write_i64, 8, [1, 2, 3, 4, 5, 6, 7, 8]);
bench_num!(f32, MAX, read_f32, write_f32, 4, [1, 2, 3, 4]);
bench_num!(f64, MAX, read_f64, write_f64, 8,
[1, 2, 3, 4, 5, 6, 7, 8]);
bench_num!(uint_1, read_uint, 1, [1]);
bench_num!(uint_2, read_uint, 2, [1, 2]);
bench_num!(uint_3, read_uint, 3, [1, 2, 3]);
bench_num!(uint_4, read_uint, 4, [1, 2, 3, 4]);
bench_num!(uint_5, read_uint, 5, [1, 2, 3, 4, 5]);
bench_num!(uint_6, read_uint, 6, [1, 2, 3, 4, 5, 6]);
bench_num!(uint_7, read_uint, 7, [1, 2, 3, 4, 5, 6, 7]);
bench_num!(uint_8, read_uint, 8, [1, 2, 3, 4, 5, 6, 7, 8]);
bench_num!(int_1, read_int, 1, [1]);
bench_num!(int_2, read_int, 2, [1, 2]);
bench_num!(int_3, read_int, 3, [1, 2, 3]);
bench_num!(int_4, read_int, 4, [1, 2, 3, 4]);
bench_num!(int_5, read_int, 5, [1, 2, 3, 4, 5]);
bench_num!(int_6, read_int, 6, [1, 2, 3, 4, 5, 6]);
bench_num!(int_7, read_int, 7, [1, 2, 3, 4, 5, 6, 7]);
bench_num!(int_8, read_int, 8, [1, 2, 3, 4, 5, 6, 7, 8]);

View File

@ -0,0 +1 @@
au BufWritePost *.rs silent!make ctags > /dev/null 2>&1

View File

@ -8,12 +8,13 @@ dependencies = [
[[package]]
name = "byteorder"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "mp4parse"
version = "0.5.0"
dependencies = [
"byteorder 0.5.3",
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -23,3 +24,5 @@ dependencies = [
"mp4parse 0.5.0",
]
[metadata]
"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"