diff options
author | Gregory Katz <gregkatz@gmail.com> | 2017-02-17 14:31:22 -0500 |
---|---|---|
committer | Gregory Katz <gregkatz@gmail.com> | 2017-02-20 12:24:45 -0500 |
commit | 214db8d9f0f6fda6ae20136442f3a28171e4b4c8 (patch) | |
tree | 272945bc02aeeb723870c43b90e5bd55f8fac764 /components/script/dom/bindings/utils.rs | |
parent | a1e4c547f042bf74c638fdff4b3faacf0b96558d (diff) | |
download | servo-214db8d9f0f6fda6ae20136442f3a28171e4b4c8.tar.gz servo-214db8d9f0f6fda6ae20136442f3a28171e4b4c8.zip |
Eliminate a mem::transmute in CodeGen
Diffstat (limited to 'components/script/dom/bindings/utils.rs')
-rw-r--r-- | components/script/dom/bindings/utils.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index de1ac8fcbfd..b5f787346f1 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -177,20 +177,20 @@ pub fn get_array_index_from_id(_cx: *mut JSContext, id: HandleId) -> Option<u32> }*/ } -/// Find the index of a string given by `v` in `values`. +/// Find the enum equivelent of a string given by `v` in `pairs`. /// Returns `Err(())` on JSAPI failure (there is a pending exception), and /// `Ok((None, value))` if there was no matching string. -pub unsafe fn find_enum_string_index(cx: *mut JSContext, +pub unsafe fn find_enum_value<'a, T>(cx: *mut JSContext, v: HandleValue, - values: &[&'static str]) - -> Result<(Option<usize>, DOMString), ()> { + pairs: &'a [(&'static str, T)]) + -> Result<(Option<&'a T>, DOMString), ()> { let jsstr = ToString(cx, v); if jsstr.is_null() { return Err(()); } let search = jsstring_to_str(cx, jsstr); - Ok((values.iter().position(|value| search == *value), search)) + Ok((pairs.iter().find(|&&(key, _)| search == *key).map(|&(_, ref ev)| ev), search)) } /// Returns wether `obj` is a platform object |