mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
clippy: Fix comparison_*
warnings (#32058)
This commit is contained in:
parent
509b858f15
commit
88d4aff595
5 changed files with 92 additions and 78 deletions
|
@ -68,7 +68,7 @@ impl DOMTokenList {
|
|||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-dtl-update
|
||||
/// <https://dom.spec.whatwg.org/#concept-dtl-update>
|
||||
fn perform_update_steps(&self, atoms: Vec<Atom>) {
|
||||
// Step 1
|
||||
if !self.element.has_attribute(&self.local_name) && atoms.is_empty() {
|
||||
|
@ -79,7 +79,7 @@ impl DOMTokenList {
|
|||
.set_atomic_tokenlist_attribute(&self.local_name, atoms)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-domtokenlist-validation
|
||||
/// <https://dom.spec.whatwg.org/#concept-domtokenlist-validation>
|
||||
fn validation_steps(&self, token: &str) -> Fallible<bool> {
|
||||
match &self.supported_tokens {
|
||||
None => Err(Error::Type(
|
||||
|
@ -99,15 +99,15 @@ impl DOMTokenList {
|
|||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#domtokenlist
|
||||
/// <https://dom.spec.whatwg.org/#domtokenlist>
|
||||
impl DOMTokenListMethods for DOMTokenList {
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-length
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-length>
|
||||
fn Length(&self) -> u32 {
|
||||
self.attribute()
|
||||
.map_or(0, |attr| attr.value().as_tokens().len()) as u32
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-item
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-item>
|
||||
fn Item(&self, index: u32) -> Option<DOMString> {
|
||||
self.attribute().and_then(|attr| {
|
||||
// FIXME(ajeffrey): Convert directly from Atom to DOMString
|
||||
|
@ -118,7 +118,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
})
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-contains
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-contains>
|
||||
fn Contains(&self, token: DOMString) -> bool {
|
||||
let token = Atom::from(token);
|
||||
self.attribute().map_or(false, |attr| {
|
||||
|
@ -129,7 +129,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
})
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-add
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-add>
|
||||
fn Add(&self, tokens: Vec<DOMString>) -> ErrorResult {
|
||||
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
|
||||
for token in &tokens {
|
||||
|
@ -142,7 +142,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-remove
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-remove>
|
||||
fn Remove(&self, tokens: Vec<DOMString>) -> ErrorResult {
|
||||
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
|
||||
for token in &tokens {
|
||||
|
@ -156,7 +156,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-toggle>
|
||||
fn Toggle(&self, token: DOMString, force: Option<bool>) -> Fallible<bool> {
|
||||
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
|
||||
let token = self.check_token_exceptions(&token)?;
|
||||
|
@ -180,18 +180,18 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-value
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-value>
|
||||
fn Value(&self) -> DOMString {
|
||||
self.element.get_string_attribute(&self.local_name)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-value
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-value>
|
||||
fn SetValue(&self, value: DOMString) {
|
||||
self.element
|
||||
.set_tokenlist_attribute(&self.local_name, value);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-replace
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-replace>
|
||||
fn Replace(&self, token: DOMString, new_token: DOMString) -> Fallible<bool> {
|
||||
if token.is_empty() || new_token.is_empty() {
|
||||
// Step 1.
|
||||
|
@ -207,23 +207,27 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
let mut atoms = self.element.get_tokenlist_attribute(&self.local_name);
|
||||
let mut result = false;
|
||||
if let Some(pos) = atoms.iter().position(|atom| *atom == token) {
|
||||
if let Some(redundant_pos) = atoms.iter().position(|atom| *atom == new_token) {
|
||||
if redundant_pos > pos {
|
||||
match atoms.iter().position(|atom| *atom == new_token) {
|
||||
Some(redundant_pos) if redundant_pos > pos => {
|
||||
// The replacement is already in the list, later,
|
||||
// so we perform the replacement and remove the
|
||||
// later copy.
|
||||
atoms[pos] = new_token;
|
||||
atoms.remove(redundant_pos);
|
||||
} else if redundant_pos < pos {
|
||||
},
|
||||
Some(redundant_pos) if redundant_pos < pos => {
|
||||
// The replacement is already in the list, earlier,
|
||||
// so we remove the index where we'd be putting the
|
||||
// later copy.
|
||||
atoms.remove(pos);
|
||||
}
|
||||
// else we are replacing the token with itself, nothing to change
|
||||
} else {
|
||||
// The replacement is not in the list already
|
||||
atoms[pos] = new_token;
|
||||
},
|
||||
Some(_) => {
|
||||
// Else we are replacing the token with itself, nothing to change
|
||||
},
|
||||
None => {
|
||||
// The replacement is not in the list already
|
||||
atoms[pos] = new_token;
|
||||
},
|
||||
}
|
||||
|
||||
// Step 5.
|
||||
|
@ -233,7 +237,7 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-supports
|
||||
/// <https://dom.spec.whatwg.org/#dom-domtokenlist-supports>
|
||||
fn Supports(&self, token: DOMString) -> Fallible<bool> {
|
||||
self.validation_steps(&token)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue