mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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:
commit
7a3d2c8cb4
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