Skip to content

Commit 0d5d2e5

Browse files
committed
core: Don't use upcall_vec_grow from str::push_char
1 parent 7a87258 commit 0d5d2e5

File tree

1 file changed

+63
-62
lines changed

1 file changed

+63
-62
lines changed

src/libcore/str.rs

+63-62
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ export
101101
native mod rustrt {
102102
fn rust_str_push(&s: str, ch: u8);
103103
fn str_reserve_shared(&ss: str, nn: libc::size_t);
104-
#[rust_stack]
105-
fn upcall_vec_grow(&s: str, new_sz: libc::size_t);
106104
}
107105

108106
/*
@@ -145,66 +143,69 @@ fn push_char(&s: str, ch: char) unsafe {
145143
else if code < max_four_b { 4u }
146144
else if code < max_five_b { 5u }
147145
else { 6u };
148-
let mut repr: *vec::unsafe::vec_repr = ::unsafe::reinterpret_cast(s);
149-
let fill = (*repr).fill;
150-
if fill + nb <= (*repr).alloc {
151-
(*repr).fill = fill + nb;
152-
} else {
153-
rustrt::upcall_vec_grow(s, fill + nb);
154-
// possibly realloc'd
155-
repr = ::unsafe::reinterpret_cast(s);
156-
}
157-
let off = fill - 1u;
158-
if nb == 1u {
159-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off) =
160-
code as u8;
161-
} else if nb == 2u {
162-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off) =
163-
(code >> 6u & 31u | tag_two_b) as u8;
164-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 1u) =
165-
(code & 63u | tag_cont) as u8;
166-
} else if nb == 3u {
167-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off) =
168-
(code >> 12u & 15u | tag_three_b) as u8;
169-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 1u) =
170-
(code >> 6u & 63u | tag_cont) as u8;
171-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 2u) =
172-
(code & 63u | tag_cont) as u8;
173-
} else if nb == 4u {
174-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off) =
175-
(code >> 18u & 7u | tag_four_b) as u8;
176-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 1u) =
177-
(code >> 12u & 63u | tag_cont) as u8;
178-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 2u) =
179-
(code >> 6u & 63u | tag_cont) as u8;
180-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 3u) =
181-
(code & 63u | tag_cont) as u8;
182-
} else if nb == 5u {
183-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off) =
184-
(code >> 24u & 3u | tag_five_b) as u8;
185-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 1u) =
186-
(code >> 18u & 63u | tag_cont) as u8;
187-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 2u) =
188-
(code >> 12u & 63u | tag_cont) as u8;
189-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 3u) =
190-
(code >> 6u & 63u | tag_cont) as u8;
191-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 4u) =
192-
(code & 63u | tag_cont) as u8;
193-
} else if nb == 6u {
194-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off) =
195-
(code >> 30u & 1u | tag_six_b) as u8;
196-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 1u) =
197-
(code >> 24u & 63u | tag_cont) as u8;
198-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 2u) =
199-
(code >> 18u & 63u | tag_cont) as u8;
200-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 3u) =
201-
(code >> 12u & 63u | tag_cont) as u8;
202-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 4u) =
203-
(code >> 6u & 63u | tag_cont) as u8;
204-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + 5u) =
205-
(code & 63u | tag_cont) as u8;
206-
}
207-
*ptr::mut_offset(ptr::mut_addr_of((*repr).data), off + nb) = 0u8;
146+
let len = len(s);
147+
let new_len = len + nb;
148+
reserve_at_least(s, new_len);
149+
let off = len;
150+
as_buf(s) {|buf|
151+
let buf: *mut u8 = ::unsafe::reinterpret_cast(buf);
152+
if nb == 1u {
153+
*ptr::mut_offset(buf, off) =
154+
code as u8;
155+
} else if nb == 2u {
156+
*ptr::mut_offset(buf, off) =
157+
(code >> 6u & 31u | tag_two_b) as u8;
158+
*ptr::mut_offset(buf, off + 1u) =
159+
(code & 63u | tag_cont) as u8;
160+
} else if nb == 3u {
161+
*ptr::mut_offset(buf, off) =
162+
(code >> 12u & 15u | tag_three_b) as u8;
163+
*ptr::mut_offset(buf, off + 1u) =
164+
(code >> 6u & 63u | tag_cont) as u8;
165+
*ptr::mut_offset(buf, off + 2u) =
166+
(code & 63u | tag_cont) as u8;
167+
} else if nb == 4u {
168+
*ptr::mut_offset(buf, off) =
169+
(code >> 18u & 7u | tag_four_b) as u8;
170+
*ptr::mut_offset(buf, off + 1u) =
171+
(code >> 12u & 63u | tag_cont) as u8;
172+
*ptr::mut_offset(buf, off + 2u) =
173+
(code >> 6u & 63u | tag_cont) as u8;
174+
*ptr::mut_offset(buf, off + 3u) =
175+
(code & 63u | tag_cont) as u8;
176+
} else if nb == 5u {
177+
*ptr::mut_offset(buf, off) =
178+
(code >> 24u & 3u | tag_five_b) as u8;
179+
*ptr::mut_offset(buf, off + 1u) =
180+
(code >> 18u & 63u | tag_cont) as u8;
181+
*ptr::mut_offset(buf, off + 2u) =
182+
(code >> 12u & 63u | tag_cont) as u8;
183+
*ptr::mut_offset(buf, off + 3u) =
184+
(code >> 6u & 63u | tag_cont) as u8;
185+
*ptr::mut_offset(buf, off + 4u) =
186+
(code & 63u | tag_cont) as u8;
187+
} else if nb == 6u {
188+
*ptr::mut_offset(buf, off) =
189+
(code >> 30u & 1u | tag_six_b) as u8;
190+
*ptr::mut_offset(buf, off + 1u) =
191+
(code >> 24u & 63u | tag_cont) as u8;
192+
*ptr::mut_offset(buf, off + 2u) =
193+
(code >> 18u & 63u | tag_cont) as u8;
194+
*ptr::mut_offset(buf, off + 3u) =
195+
(code >> 12u & 63u | tag_cont) as u8;
196+
*ptr::mut_offset(buf, off + 4u) =
197+
(code >> 6u & 63u | tag_cont) as u8;
198+
*ptr::mut_offset(buf, off + 5u) =
199+
(code & 63u | tag_cont) as u8;
200+
}
201+
*ptr::mut_offset(buf, off + nb) = 0u8;
202+
}
203+
204+
as_bytes(s) {|bytes|
205+
let mut mut_bytes: [u8] = ::unsafe::reinterpret_cast(bytes);
206+
vec::unsafe::set_len(mut_bytes, new_len + 1u);
207+
::unsafe::forget(mut_bytes);
208+
}
208209
}
209210

210211
#[doc = "Convert a char to a string"]

0 commit comments

Comments
 (0)