Skip to content

Commit aa0c1be

Browse files
committed
---
yaml --- r: 36780 b: refs/heads/try2 c: 8311c94 h: refs/heads/master v: v3
1 parent 277e8c0 commit aa0c1be

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 70fbdb95809e94e3c6537eac78d47656a601bfe3
8+
refs/heads/try2: 8311c94db47c1dad52045a312082b0302d79b79d
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/libcore/uint-template.rs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
179179
f: fn(v: &[u8]) -> U) -> U {
180180

181181
#[inline(always)]
182-
fn digit(n: T) -> u8 {
182+
pure fn digit(n: T) -> u8 {
183183
if n <= 9u as T {
184184
n as u8 + '0' as u8
185185
} else if n <= 15u as T {
@@ -195,35 +195,27 @@ pub pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
195195
// Worst case: 64-bit number, binary-radix, with
196196
// a leading negative sign = 65 bytes.
197197
let buf : [mut u8 * 65] = [mut 0u8, ..65];
198+
let len = buf.len();
198199

199-
// FIXME (#2649): post-snapshot, you can do this without the raw
200-
// pointers and unsafe bits, and the codegen will prove it's all
201-
// in-bounds, no extra cost.
202-
203-
unsafe {
204-
do vec::as_imm_buf(buf) |p, len| {
205-
let mp = p as *mut u8;
206-
let mut i = len;
207-
let mut n = num;
208-
let radix = radix as T;
209-
loop {
210-
i -= 1u;
211-
assert 0u < i && i < len;
212-
*ptr::mut_offset(mp, i) = digit(n % radix);
213-
n /= radix;
214-
if n == 0 as T { break; }
215-
}
216-
217-
assert 0u < i && i < len;
218-
219-
if neg {
220-
i -= 1u;
221-
*ptr::mut_offset(mp, i) = '-' as u8;
222-
}
223-
224-
vec::raw::buf_as_slice(ptr::offset(p, i), len - i, f)
225-
}
200+
let mut i = len;
201+
let mut n = num;
202+
let radix = radix as T;
203+
loop {
204+
i -= 1u;
205+
assert 0u < i && i < len;
206+
buf[i] = digit(n % radix);
207+
n /= radix;
208+
if n == 0 as T { break; }
209+
}
210+
211+
assert 0u < i && i < len;
212+
213+
if neg {
214+
i -= 1u;
215+
buf[i] = '-' as u8;
226216
}
217+
218+
f(vec::view(buf, i, len))
227219
}
228220

229221
/// Convert to a string

0 commit comments

Comments
 (0)