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):
|
def __init__(self, enum):
|
||||||
CGThing.__init__(self)
|
CGThing.__init__(self)
|
||||||
inner = """
|
inner = """
|
||||||
use dom::bindings::utils::EnumEntry;
|
|
||||||
#[repr(uint)]
|
#[repr(uint)]
|
||||||
pub enum valuelist {
|
pub enum valuelist {
|
||||||
%s
|
%s
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static strings: &'static [EnumEntry] = &[
|
pub static strings: &'static [&'static str] = &[
|
||||||
%s,
|
%s,
|
||||||
];
|
];
|
||||||
""" % (",\n ".join(map(getEnumValueName, enum.values())),
|
""" % (",\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([
|
self.cgRoot = CGList([
|
||||||
CGNamespace.build([enum.identifier.name + "Values"],
|
CGNamespace.build([enum.identifier.name + "Values"],
|
||||||
|
|
|
@ -566,14 +566,9 @@ pub fn InitIds(cx: *JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bo
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EnumEntry {
|
|
||||||
value: &'static str,
|
|
||||||
length: uint
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn FindEnumStringIndex(cx: *JSContext,
|
pub fn FindEnumStringIndex(cx: *JSContext,
|
||||||
v: JSVal,
|
v: JSVal,
|
||||||
values: &[EnumEntry]) -> Result<uint, ()> {
|
values: &[&'static str]) -> Result<uint, ()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let jsstr = JS_ValueToString(cx, v);
|
let jsstr = JS_ValueToString(cx, v);
|
||||||
if jsstr.is_null() {
|
if jsstr.is_null() {
|
||||||
|
@ -585,16 +580,10 @@ pub fn FindEnumStringIndex(cx: *JSContext,
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
for (i, value) in values.iter().enumerate() {
|
for (i, value) in values.iter().enumerate() {
|
||||||
if value.length != length as uint {
|
let equal = value.len() == length as uint &&
|
||||||
continue;
|
range(0, length as int).all(|j| {
|
||||||
}
|
value[j] as u16 == *chars.offset(j)
|
||||||
let mut equal = true;
|
});
|
||||||
for j in range(0, length as int) {
|
|
||||||
if value.value[j] as u16 != *chars.offset(j) {
|
|
||||||
equal = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if equal {
|
if equal {
|
||||||
return Ok(i);
|
return Ok(i);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue