Commit Graph

30 Commits

Author SHA1 Message Date
Erick Tryzelaar
b1ee87f402 std: simplify vec.with_c_str
This also fixes a bug in `vec.with_c_str_unchecked` where we
were not calling `.to_c_str_unchecked()` for long strings.
2013-09-26 22:49:10 -07:00
Erick Tryzelaar
2d878033fd std: add micro optimization to vec.with_c_str_unchecked
before:

test c_str::bench::bench_with_c_str_unchecked_long ... bench: 361 ns/iter (+/- 9)
test c_str::bench::bench_with_c_str_unchecked_medium ... bench: 75 ns/iter (+/- 2)
test c_str::bench::bench_with_c_str_unchecked_short ... bench: 60 ns/iter (+/- 9)

after:

test c_str::bench::bench_with_c_str_unchecked_long ... bench: 362 ns/iter (+/-
test c_str::bench::bench_with_c_str_unchecked_medium ... bench: 30 ns/iter (+/- 7)
test c_str::bench::bench_with_c_str_unchecked_short ... bench: 12 ns/iter (+/- 4)
2013-09-26 22:20:40 -07:00
Erick Tryzelaar
4868273d97 std: Up vec.with_c_str's stack buffer to 128
This matches @graydon's recommendation.
2013-09-26 22:20:40 -07:00
Erick Tryzelaar
ca66b81283 std: Remove an unnecessary comment from c_str
The documentation for `.with_c_str()` already says that the pointer
will be deallocated before returning from the function.
2013-09-26 22:20:40 -07:00
Erick Tryzelaar
e02d1eb171 std: Micro-optimize vec.with_c_str for short vectors
This now makes it unsafe to save the pointer returned by .with_c_str
as that pointer now may be pointing at a stack allocated array.

I arbitrarily chose 32 bytes as the length of the stack vector, and
so it might not be the most optimal size.

before:

test c_str::bench::bench_with_c_str_long ... bench: 539 ns/iter (+/- 91)
test c_str::bench::bench_with_c_str_medium ... bench: 97 ns/iter (+/- 2)
test c_str::bench::bench_with_c_str_short ... bench: 70 ns/iter (+/- 5)

after:

test c_str::bench::bench_with_c_str_long ... bench: 542 ns/iter (+/- 13)
test c_str::bench::bench_with_c_str_medium ... bench: 53 ns/iter (+/- 6)
test c_str::bench::bench_with_c_str_short ... bench: 19 ns/iter (+/- 0)
2013-09-26 22:20:40 -07:00
Erick Tryzelaar
410a96cc79 std: Add benchmarks to c_str 2013-09-26 22:20:40 -07:00
Erick Tryzelaar
2a9e763304 std: implement Container for CString 2013-09-26 22:20:39 -07:00
Alex Crichton
3585c64d09 rustdoc: Change all code-blocks with a script
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g'
    find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g'
    find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-09-25 14:27:42 -07:00
bors
a95604fcaa auto merge of #9276 : alexcrichton/rust/dox, r=brson
Hopefull this will make our libstd docs appear a little more "full".
2013-09-20 14:11:08 -07:00
Alex Crichton
817576ee70 Register new snapshots 2013-09-18 11:07:22 -07:00
Alex Crichton
88bc11e646 Document a few undocumented modules in libstd
Hopefull this will make our libstd docs appear a little more "full".
2013-09-17 20:50:23 -07:00
Daniel Micay
4e161a4d40 switch Drop to &mut self 2013-09-16 22:19:23 -04:00
Kevin Ballard
51470f3b97 c_str: Add new method .as_str() -> Option<&str>
Also rustify .as_bytes(), so it no longer calls libc::strlen() and is
inlineable.
2013-09-15 20:30:03 -07:00
Daniel Micay
6919cf5fe1 rename std::iterator to std::iter
The trait will keep the `Iterator` naming, but a more concise module
name makes using the free functions less verbose. The module will define
iterables in addition to iterators, as it deals with iteration in
general.
2013-09-09 03:21:46 -04:00
Felix S. Klock II
83e19d2ead Added explicit pub to several conditions. Enables completion of #6009. 2013-09-04 10:03:47 +02:00
jmgrosen
4a18d46130 Fixes #8881. condition! imports parent's pub identifiers 2013-09-03 16:11:00 -07:00
Alex Crichton
e3662b1880 Remove offset_inbounds for an unsafe offset function 2013-08-27 23:22:52 -07:00
Vadim Chugunov
12ecdb6381 Enabled unit tests in std and extra. 2013-08-22 20:02:20 -07:00
Niko Matsakis
0479d946c8 Add externfn macro and correctly label fixed_stack_segments 2013-08-19 07:13:15 -04:00
Kevin Ballard
f744cf157e Make CString.iter() public 2013-08-15 01:33:10 -07:00
Kevin Ballard
03ef71e262 Add ToCStr method .with_c_str()
.with_c_str() is a replacement for the old .as_c_str(), to avoid
unnecessary boilerplate.

Replace all usages of .to_c_str().with_ref() with .with_c_str().
2013-08-15 01:33:10 -07:00
Kevin Ballard
48265b779f Check for interior nulls in .to_c_str()
Previous dicussions about CString suggested that interior nulls should
throw an error. This was never implemented. Add this now, using a
condition (named null_byte) to allow for recovery.

Add method .to_c_str_unchecked() that skips this check.
2013-08-15 01:32:10 -07:00
Kevin Ballard
1e4f13f95f Clarify docs on CString.unwrap()
CString.unwrap() drops ownership of the buffer on the floor. Put this in
the docs.
2013-08-14 19:18:24 -07:00
Erick Tryzelaar
aababbba8e std: fix a bad type cast for in str.to_c_str() 2013-08-07 14:06:50 -07:00
Erick Tryzelaar
72688eaa13 std: Make CString::new unsafe b/c it can mutate a *T ptr 2013-08-07 14:06:50 -07:00
Erick Tryzelaar
d6257b315b std: remove unnecessary test from c_str.drop and use safer transmute 2013-08-07 14:06:50 -07:00
Erick Tryzelaar
e053bff5d0 std: Fix c_str.iter() and add test 2013-08-07 14:06:45 -07:00
Erick Tryzelaar
fb9b27910b std: c_str should use regions on methods 2013-08-05 19:55:07 -07:00
Erick Tryzelaar
986ba9c3c1 std: Update the c_str docs, and support CString not owning the pointer 2013-08-04 18:37:55 -07:00
Erick Tryzelaar
3102b1797e std: replace str::as_c_str with std::c_str 2013-08-04 14:13:17 -07:00