mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
script: Stop reallocating so much when converting DOM strings to JS
values. `size_hint()` in `utf16_units()` seems busted, so we do it ourselves.
This commit is contained in:
parent
9523283c14
commit
f2f91886ee
1 changed files with 2 additions and 1 deletions
|
@ -394,8 +394,9 @@ impl<T: Float + FromJSValConvertible<Config=()>> FromJSValConvertible for Finite
|
|||
|
||||
impl ToJSValConvertible for str {
|
||||
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||
let mut string_utf16: Vec<u16> = Vec::with_capacity(self.len());
|
||||
unsafe {
|
||||
let string_utf16: Vec<u16> = self.utf16_units().collect();
|
||||
string_utf16.extend(self.utf16_units());
|
||||
let jsstr = JS_NewUCStringCopyN(cx, string_utf16.as_ptr() as *const i16,
|
||||
string_utf16.len() as libc::size_t);
|
||||
if jsstr.is_null() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue