replace .len() == 0 with is_empty()

closes #7198
This commit is contained in:
João Oliveira 2015-08-14 03:55:02 +01:00
parent f5e97ef1b5
commit 9c11781880
20 changed files with 25 additions and 29 deletions

View file

@ -710,7 +710,7 @@ fn write_image(draw_target: &DrawTarget,
smoothing_enabled: bool, smoothing_enabled: bool,
composition_op: CompositionOp, composition_op: CompositionOp,
global_alpha: f32) { global_alpha: f32) {
if image_data.len() == 0 { if image_data.is_empty() {
return return
} }
let image_rect = Rect::new(Point2D::zero(), image_size); let image_rect = Rect::new(Point2D::zero(), image_size);

View file

@ -1320,7 +1320,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
// Return unused tiles first, so that they can be reused by any new BufferRequests. // Return unused tiles first, so that they can be reused by any new BufferRequests.
self.cache_unused_buffers(unused_buffers); self.cache_unused_buffers(unused_buffers);
if layers_and_requests.len() == 0 { if layers_and_requests.is_empty() {
return false; return false;
} }
@ -1803,4 +1803,3 @@ pub enum CompositingReason {
/// The window has been zoomed. /// The window has been zoomed.
Zoom, Zoom,
} }

View file

@ -586,7 +586,7 @@ impl StackingContext {
pub fn print(&self, mut indentation: String) { pub fn print(&self, mut indentation: String) {
// We cover the case of an empty string. // We cover the case of an empty string.
if indentation.len() == 0 { if indentation.is_empty() {
indentation = "####".to_owned(); indentation = "####".to_owned();
} }

View file

@ -190,7 +190,7 @@ impl FontCache {
debug!("FontList: Found font family with name={}", &**family_name); debug!("FontList: Found font family with name={}", &**family_name);
let s = self.local_families.get_mut(family_name).unwrap(); let s = self.local_families.get_mut(family_name).unwrap();
if s.templates.len() == 0 { if s.templates.is_empty() {
get_variations_for_family(family_name, |path| { get_variations_for_family(family_name, |path| {
s.add_template(Atom::from_slice(&path), None); s.add_template(Atom::from_slice(&path), None);
}); });

View file

@ -222,7 +222,7 @@ impl FontContext {
// If unable to create any of the specified fonts, create one from the // If unable to create any of the specified fonts, create one from the
// list of last resort fonts for this platform. // list of last resort fonts for this platform.
if fonts.len() == 0 { if fonts.is_empty() {
let mut cache_hit = false; let mut cache_hit = false;
for cached_font_entry in self.fallback_font_cache.iter() { for cached_font_entry in self.fallback_font_cache.iter() {
let cached_font = cached_font_entry.font.borrow(); let cached_font = cached_font_entry.font.borrow();

View file

@ -707,7 +707,7 @@ impl<'a> FlowConstructor<'a> {
style: &Arc<ComputedValues>) { style: &Arc<ComputedValues>) {
// Fast path: If there is no text content, return immediately. // Fast path: If there is no text content, return immediately.
let text_content = node.text_content(); let text_content = node.text_content();
if text_content.len() == 0 { if text_content.is_empty() {
return return
} }

View file

@ -571,8 +571,8 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
&mut applicable_declarations.after); &mut applicable_declarations.after);
*shareable = applicable_declarations.normal_shareable && *shareable = applicable_declarations.normal_shareable &&
applicable_declarations.before.len() == 0 && applicable_declarations.before.is_empty() &&
applicable_declarations.after.len() == 0 applicable_declarations.after.is_empty()
} }
unsafe fn share_style_if_possible(&self, unsafe fn share_style_if_possible(&self,

View file

@ -1238,7 +1238,7 @@ impl<'a> ImmutableFlowUtils for &'a (Flow + 'a) {
/// Returns true if this flow has no children. /// Returns true if this flow has no children.
fn is_leaf(self) -> bool { fn is_leaf(self) -> bool {
base(self).children.len() == 0 base(self).children.is_empty()
} }
/// Returns the number of children that this flow possesses. /// Returns the number of children that this flow possesses.

View file

@ -182,7 +182,7 @@ impl ImageCache {
// Can only exit when all pending loads are complete. // Can only exit when all pending loads are complete.
if let Some(ref exit_sender) = exit_sender { if let Some(ref exit_sender) = exit_sender {
if self.pending_loads.len() == 0 { if self.pending_loads.is_empty() {
exit_sender.send(()).unwrap(); exit_sender.send(()).unwrap();
break; break;
} }
@ -388,4 +388,3 @@ pub fn new_image_cache_task(resource_task: ResourceTask) -> ImageCacheTask {
ImageCacheTask::new(ipc_command_sender) ImageCacheTask::new(ipc_command_sender)
} }

View file

@ -44,7 +44,7 @@ fn byte_swap_and_premultiply(data: &mut [u8]) {
} }
pub fn load_from_memory(buffer: &[u8]) -> Option<Image> { pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
if buffer.len() == 0 { if buffer.is_empty() {
return None; return None;
} }
@ -120,5 +120,3 @@ fn is_gif(buffer: &[u8]) -> bool {
_ => false _ => false
} }
} }

View file

@ -83,7 +83,7 @@ impl LintPass for InheritancePass {
cx.sess().span_note(*span, "Bare DOM struct found here"); cx.sess().span_note(*span, "Bare DOM struct found here");
} }
} }
} else if dom_spans.len() == 0 { } else if dom_spans.is_empty() {
cx.span_lint(INHERITANCE_INTEGRITY, cx.tcx.map.expect_item(id).span, cx.span_lint(INHERITANCE_INTEGRITY, cx.tcx.map.expect_item(id).span,
"This DOM struct has no reflector or parent DOM struct"); "This DOM struct has no reflector or parent DOM struct");
} }

View file

@ -232,7 +232,7 @@ impl CORSRequest {
_ => return error _ => return error
}; };
// Substep 4 // Substep 4
if methods.len() == 0 || preflight.mode == RequestMode::ForcedPreflight { if methods.is_empty() || preflight.mode == RequestMode::ForcedPreflight {
methods = &methods_substep4; methods = &methods_substep4;
} }
// Substep 5 // Substep 5

View file

@ -50,7 +50,7 @@ impl ByteString {
/// [RFC 2616](http://tools.ietf.org/html/rfc2616#page-17). /// [RFC 2616](http://tools.ietf.org/html/rfc2616#page-17).
pub fn is_token(&self) -> bool { pub fn is_token(&self) -> bool {
let ByteString(ref vec) = *self; let ByteString(ref vec) = *self;
if vec.len() == 0 { if vec.is_empty() {
return false; // A token must be at least a single character return false; // A token must be at least a single character
} }
vec.iter().all(|&x| { vec.iter().all(|&x| {

View file

@ -970,7 +970,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
/// https://html.spec.whatwg.org/multipage/#dom-window-cancelanimationframe /// https://html.spec.whatwg.org/multipage/#dom-window-cancelanimationframe
fn cancel_animation_frame(self, ident: i32) { fn cancel_animation_frame(self, ident: i32) {
self.animation_frame_list.borrow_mut().remove(&ident); self.animation_frame_list.borrow_mut().remove(&ident);
if self.animation_frame_list.borrow().len() == 0 { if self.animation_frame_list.borrow().is_empty() {
let window = self.window.root(); let window = self.window.root();
let window = window.r(); let window = window.r();
let ConstellationChan(ref chan) = window.constellation_chan(); let ConstellationChan(ref chan) = window.constellation_chan();

View file

@ -231,7 +231,7 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement {
} }
// Step 4. // Step 4.
let text = self.Text(); let text = self.Text();
if text.len() == 0 && !element.has_attribute(&atom!("src")) { if text.is_empty() && !element.has_attribute(&atom!("src")) {
return NextParserState::Continue; return NextParserState::Continue;
} }
// Step 5. // Step 5.

View file

@ -2135,7 +2135,7 @@ impl<'a> NodeMethods for &'a Node {
NodeTypeId::DocumentFragment | NodeTypeId::DocumentFragment |
NodeTypeId::Element(..) => { NodeTypeId::Element(..) => {
// Step 1-2. // Step 1-2.
let node = if value.len() == 0 { let node = if value.is_empty() {
None None
} else { } else {
let document = self.owner_doc(); let document = self.owner_doc();

View file

@ -497,7 +497,7 @@ impl<'a> XMLHttpRequestMethods for &'a XMLHttpRequest {
// Step 7 // Step 7
self.upload_complete.set(match extracted { self.upload_complete.set(match extracted {
None => true, None => true,
Some (ref v) if v.len() == 0 => true, Some (ref v) if v.is_empty() => true,
_ => false _ => false
}); });

View file

@ -121,14 +121,14 @@ pub enum LengthOrPercentageOrAuto {
/// Parses a length per HTML5 § 2.4.4.4. If unparseable, `Auto` is returned. /// Parses a length per HTML5 § 2.4.4.4. If unparseable, `Auto` is returned.
pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto { pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
value = value.trim_left_matches(WHITESPACE); value = value.trim_left_matches(WHITESPACE);
if value.len() == 0 { if value.is_empty() {
return LengthOrPercentageOrAuto::Auto return LengthOrPercentageOrAuto::Auto
} }
if value.starts_with("+") { if value.starts_with("+") {
value = &value[1..] value = &value[1..]
} }
value = value.trim_left_matches('0'); value = value.trim_left_matches('0');
if value.len() == 0 { if value.is_empty() {
return LengthOrPercentageOrAuto::Auto return LengthOrPercentageOrAuto::Auto
} }
@ -171,7 +171,7 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
/// Parses a legacy color per HTML5 § 2.4.6. If unparseable, `Err` is returned. /// Parses a legacy color per HTML5 § 2.4.6. If unparseable, `Err` is returned.
pub fn parse_legacy_color(mut input: &str) -> Result<RGBA,()> { pub fn parse_legacy_color(mut input: &str) -> Result<RGBA,()> {
// Steps 1 and 2. // Steps 1 and 2.
if input.len() == 0 { if input.is_empty() {
return Err(()) return Err(())
} }
@ -243,7 +243,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA,()> {
let mut input = new_input; let mut input = new_input;
// Step 11. // Step 11.
while input.len() == 0 || (input.len() % 3) != 0 { while input.is_empty() || (input.len() % 3) != 0 {
input.push(b'0') input.push(b'0')
} }

View file

@ -35,7 +35,7 @@ impl<T: Ord + PartialOrd + PartialEq> BinarySearchMethods<T> for [T] {
impl<T> FullBinarySearchMethods<T> for [T] { impl<T> FullBinarySearchMethods<T> for [T] {
fn binary_search_index_by<K,C:Comparator<K,T>>(&self, key: &K, cmp: C) -> Option<usize> { fn binary_search_index_by<K,C:Comparator<K,T>>(&self, key: &K, cmp: C) -> Option<usize> {
if self.len() == 0 { if self.is_empty() {
return None; return None;
} }

View file

@ -20,7 +20,7 @@ pub extern "C" fn cef_string_multimap_alloc() -> *mut cef_string_multimap_t {
pub extern "C" fn cef_string_multimap_size(smm: *mut cef_string_multimap_t) -> c_int { pub extern "C" fn cef_string_multimap_size(smm: *mut cef_string_multimap_t) -> c_int {
unsafe { unsafe {
if smm.is_null() { return 0; } if smm.is_null() { return 0; }
// t1 : collections::btree::map::Values<'_, collections::string::String, collections::vec::Vec<*mut types::cef_string_utf16>>` // t1 : collections::btree::map::Values<'_, collections::string::String, collections::vec::Vec<*mut types::cef_string_utf16>>`
let t1 = (*smm).values(); let t1 = (*smm).values();
// t2 : collections::btree::map::BTreeMap<collections::string::String, collections::vec::Vec<*mut types::cef_string_utf16>> // t2 : collections::btree::map::BTreeMap<collections::string::String, collections::vec::Vec<*mut types::cef_string_utf16>>
let t2 : usize = t1.map(|val| (*val).len()).sum(); let t2 : usize = t1.map(|val| (*val).len()).sum();
@ -118,7 +118,7 @@ pub extern "C" fn cef_string_multimap_value(smm: *mut cef_string_multimap_t, ind
pub extern "C" fn cef_string_multimap_clear(smm: *mut cef_string_multimap_t) { pub extern "C" fn cef_string_multimap_clear(smm: *mut cef_string_multimap_t) {
unsafe { unsafe {
if smm.is_null() { return; } if smm.is_null() { return; }
if (*smm).len() == 0 { return; } if (*smm).is_empty() { return; }
for (_, val) in (*smm).iter_mut() { for (_, val) in (*smm).iter_mut() {
while let Some(cs) = (*val).pop() { while let Some(cs) = (*val).pop() {
cef_string_userfree_utf16_free(cs); cef_string_userfree_utf16_free(cs);