mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Remove EnumEntry, as Rust already provides O(1) access to the string length.
This commit is contained in:
parent
3e0d4a2509
commit
9a909229e3
2 changed files with 7 additions and 19 deletions
|
@ -2909,17 +2909,16 @@ class CGEnum(CGThing):
|
|||
def __init__(self, enum):
|
||||
CGThing.__init__(self)
|
||||
inner = """
|
||||
use dom::bindings::utils::EnumEntry;
|
||||
#[repr(uint)]
|
||||
pub enum valuelist {
|
||||
%s
|
||||
}
|
||||
|
||||
pub static strings: &'static [EnumEntry] = &[
|
||||
pub static strings: &'static [&'static str] = &[
|
||||
%s,
|
||||
];
|
||||
""" % (",\n ".join(map(getEnumValueName, enum.values())),
|
||||
",\n ".join(['EnumEntry {value: &"' + val + '", length: ' + str(len(val)) + '}' for val in enum.values()]))
|
||||
",\n ".join(['&"%s"' % val for val in enum.values()]))
|
||||
|
||||
self.cgRoot = CGList([
|
||||
CGNamespace.build([enum.identifier.name + "Values"],
|
||||
|
|
|
@ -566,14 +566,9 @@ pub fn InitIds(cx: *JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bo
|
|||
true
|
||||
}
|
||||
|
||||
pub struct EnumEntry {
|
||||
value: &'static str,
|
||||
length: uint
|
||||
}
|
||||
|
||||
pub fn FindEnumStringIndex(cx: *JSContext,
|
||||
v: JSVal,
|
||||
values: &[EnumEntry]) -> Result<uint, ()> {
|
||||
values: &[&'static str]) -> Result<uint, ()> {
|
||||
unsafe {
|
||||
let jsstr = JS_ValueToString(cx, v);
|
||||
if jsstr.is_null() {
|
||||
|
@ -585,16 +580,10 @@ pub fn FindEnumStringIndex(cx: *JSContext,
|
|||
return Err(());
|
||||
}
|
||||
for (i, value) in values.iter().enumerate() {
|
||||
if value.length != length as uint {
|
||||
continue;
|
||||
}
|
||||
let mut equal = true;
|
||||
for j in range(0, length as int) {
|
||||
if value.value[j] as u16 != *chars.offset(j) {
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
};
|
||||
let equal = value.len() == length as uint &&
|
||||
range(0, length as int).all(|j| {
|
||||
value[j] as u16 == *chars.offset(j)
|
||||
});
|
||||
|
||||
if equal {
|
||||
return Ok(i);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue