Auto merge of #7765 - pcwalton:less-ambitious-low-hanging-dromaeo-fruit, r=jdm

script: Stop reallocating so much when converting DOM strings to JS values.

This is split out from #6900.

`size_hint()` in `utf16_units()` seems busted, so we do it ourselves.

r? @jdm

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7765)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-27 17:47:38 -06:00
commit 7a3d2c8cb4

View file

@ -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() {