Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #57830

Merged
merged 21 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0f34e0d
Add fmt benchmarks
sinkuu Jan 11, 2019
d7a7ce9
Utilize specialized zip iterator impl
sinkuu Jan 11, 2019
038d837
Fix simple formatting optimization
sinkuu Jan 12, 2019
763392c
Fix memory leak in P::filter_map
ishitatsuyuki Jan 16, 2019
c7d25a2
Make `str` indexing generic on `SliceIndex`.
Jan 14, 2019
2200fd3
Add default rust logo for documentation
GuillaumeGomez Jan 12, 2019
98d4f33
const_eval: Predetermine the layout of all locals when pushing a stac…
dotdash Jan 16, 2019
b5d167f
Add default favicon for documentation
GuillaumeGomez Jan 12, 2019
3ecbe1e
Add regression test for #54582
estebank Jan 21, 2019
58b0200
Add powerpc64-unknown-freebsd
Jan 21, 2019
400e28d
fix validation range printing when encountering undef
RalfJung Jan 21, 2019
051835b
Corrected spelling inconsistency
Jan 21, 2019
e437861
Rollup merge of #57537 - sinkuu:fmt_perf, r=alexcrichton
Centril Jan 22, 2019
e3d3cff
Rollup merge of #57552 - GuillaumeGomez:default-images, r=QuietMisdre…
Centril Jan 22, 2019
ad55b73
Rollup merge of #57604 - alercah:str-index, r=sfackler
Centril Jan 22, 2019
7fb44e8
Rollup merge of #57667 - ishitatsuyuki:p-leak, r=nnethercote
Centril Jan 22, 2019
973e754
Rollup merge of #57677 - dotdash:locals, r=michaelwoerister
Centril Jan 22, 2019
892e693
Rollup merge of #57791 - estebank:issue-54582, r=zackmdavis
Centril Jan 22, 2019
8c55115
Rollup merge of #57798 - hellow554:master, r=davidtwco
Centril Jan 22, 2019
e3849cc
Rollup merge of #57809 - MikaelUrankar:powerpc64-unknown-freebsd, r=n…
Centril Jan 22, 2019
dec7b7b
Rollup merge of #57813 - RalfJung:validation-range-printing, r=oli-obk
Centril Jan 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions src/libcore/benches/fmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use std::io::{self, Write as IoWrite};
use std::fmt::{self, Write as FmtWrite};
use test::Bencher;

#[bench]
fn write_vec_value(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = Vec::new();
for _ in 0..1000 {
mem.write_all("abc".as_bytes()).unwrap();
}
});
}

#[bench]
fn write_vec_ref(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = Vec::new();
let wr = &mut mem as &mut dyn io::Write;
for _ in 0..1000 {
wr.write_all("abc".as_bytes()).unwrap();
}
});
}

#[bench]
fn write_vec_macro1(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = Vec::new();
let wr = &mut mem as &mut dyn io::Write;
for _ in 0..1000 {
write!(wr, "abc").unwrap();
}
});
}

#[bench]
fn write_vec_macro2(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = Vec::new();
let wr = &mut mem as &mut dyn io::Write;
for _ in 0..1000 {
write!(wr, "{}", "abc").unwrap();
}
});
}

#[bench]
fn write_vec_macro_debug(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = Vec::new();
let wr = &mut mem as &mut dyn io::Write;
for _ in 0..1000 {
write!(wr, "{:?}", "☃").unwrap();
}
});
}

#[bench]
fn write_str_value(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = String::new();
for _ in 0..1000 {
mem.write_str("abc").unwrap();
}
});
}

#[bench]
fn write_str_ref(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = String::new();
let wr = &mut mem as &mut dyn fmt::Write;
for _ in 0..1000 {
wr.write_str("abc").unwrap();
}
});
}

#[bench]
fn write_str_macro1(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = String::new();
for _ in 0..1000 {
write!(mem, "abc").unwrap();
}
});
}

#[bench]
fn write_str_macro2(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = String::new();
let wr = &mut mem as &mut dyn fmt::Write;
for _ in 0..1000 {
write!(wr, "{}", "abc").unwrap();
}
});
}

#[bench]
fn write_str_macro_debug(bh: &mut Bencher) {
bh.iter(|| {
let mut mem = String::new();
let wr = &mut mem as &mut dyn fmt::Write;
for _ in 0..1000 {
write!(wr, "{:?}", "☃").unwrap();
}
});
}
1 change: 1 addition & 0 deletions src/libcore/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ mod iter;
mod num;
mod ops;
mod slice;
mod fmt;
10 changes: 6 additions & 4 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,28 +1006,30 @@ pub fn write(output: &mut dyn Write, args: Arguments) -> Result {
curarg: args.args.iter(),
};

let mut pieces = args.pieces.iter();
let mut idx = 0;

match args.fmt {
None => {
// We can use default formatting parameters for all arguments.
for (arg, piece) in args.args.iter().zip(pieces.by_ref()) {
for (arg, piece) in args.args.iter().zip(args.pieces.iter()) {
formatter.buf.write_str(*piece)?;
(arg.formatter)(arg.value, &mut formatter)?;
idx += 1;
}
}
Some(fmt) => {
// Every spec has a corresponding argument that is preceded by
// a string piece.
for (arg, piece) in fmt.iter().zip(pieces.by_ref()) {
for (arg, piece) in fmt.iter().zip(args.pieces.iter()) {
formatter.buf.write_str(*piece)?;
formatter.run(arg)?;
idx += 1;
}
}
}

// There can be only one trailing string piece left.
if let Some(piece) = pieces.next() {
if let Some(piece) = args.pieces.get(idx) {
formatter.buf.write_str(*piece)?;
}

Expand Down
15 changes: 0 additions & 15 deletions src/libcore/ops/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@
/// ```
#[lang = "index"]
#[rustc_on_unimplemented(
on(
_Self="&str",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
on(
_Self="str",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
on(
_Self="std::string::String",
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
message="the type `{Self}` cannot be indexed by `{Idx}`",
label="`{Self}` cannot be indexed by `{Idx}`",
)]
Expand Down
16 changes: 13 additions & 3 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2383,7 +2383,6 @@ impl [u8] {
}

#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`"]
impl<T, I> ops::Index<I> for [T]
where I: SliceIndex<[T]>
{
Expand All @@ -2396,7 +2395,6 @@ impl<T, I> ops::Index<I> for [T]
}

#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`"]
impl<T, I> ops::IndexMut<I> for [T]
where I: SliceIndex<[T]>
{
Expand Down Expand Up @@ -2447,7 +2445,19 @@ mod private_slice_index {

/// A helper trait used for indexing operations.
#[stable(feature = "slice_get_slice", since = "1.28.0")]
#[rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`"]
#[rustc_on_unimplemented(
on(
T = "str",
label = "string indices are ranges of `usize`",
),
on(
all(any(T = "str", T = "&str", T = "std::string::String"), _Self="{integer}"),
note="you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
),
message = "the type `{T}` cannot be indexed by `{Self}`",
label = "slice indices are of type `usize` or ranges of `usize`",
)]
pub trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
/// The output type returned by methods.
#[stable(feature = "slice_get_slice", since = "1.28.0")]
Expand Down
Loading