Skip to content
Permalink
Browse files

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

closes #7198
  • Loading branch information...
jxs committed Aug 14, 2015
1 parent f5e97ef commit 9c117818800b69f04f76e4f7afd92b2660752bae
@@ -710,7 +710,7 @@ fn write_image(draw_target: &DrawTarget,
smoothing_enabled: bool,
composition_op: CompositionOp,
global_alpha: f32) {
if image_data.len() == 0 {
if image_data.is_empty() {
return
}
let image_rect = Rect::new(Point2D::zero(), image_size);
@@ -1320,7 +1320,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
// Return unused tiles first, so that they can be reused by any new BufferRequests.
self.cache_unused_buffers(unused_buffers);

if layers_and_requests.len() == 0 {
if layers_and_requests.is_empty() {
return false;
}

@@ -1803,4 +1803,3 @@ pub enum CompositingReason {
/// The window has been zoomed.
Zoom,
}

@@ -586,7 +586,7 @@ impl StackingContext {

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

@@ -190,7 +190,7 @@ impl FontCache {
debug!("FontList: Found font family with name={}", &**family_name);
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| {
s.add_template(Atom::from_slice(&path), None);
});
@@ -222,7 +222,7 @@ impl FontContext {

// If unable to create any of the specified fonts, create one from the
// list of last resort fonts for this platform.
if fonts.len() == 0 {
if fonts.is_empty() {
let mut cache_hit = false;
for cached_font_entry in self.fallback_font_cache.iter() {
let cached_font = cached_font_entry.font.borrow();
@@ -707,7 +707,7 @@ impl<'a> FlowConstructor<'a> {
style: &Arc<ComputedValues>) {
// Fast path: If there is no text content, return immediately.
let text_content = node.text_content();
if text_content.len() == 0 {
if text_content.is_empty() {
return
}

@@ -571,8 +571,8 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
&mut applicable_declarations.after);

*shareable = applicable_declarations.normal_shareable &&
applicable_declarations.before.len() == 0 &&
applicable_declarations.after.len() == 0
applicable_declarations.before.is_empty() &&
applicable_declarations.after.is_empty()
}

unsafe fn share_style_if_possible(&self,
@@ -1238,7 +1238,7 @@ impl<'a> ImmutableFlowUtils for &'a (Flow + 'a) {

/// Returns true if this flow has no children.
fn is_leaf(self) -> bool {
base(self).children.len() == 0
base(self).children.is_empty()
}

/// Returns the number of children that this flow possesses.
@@ -182,7 +182,7 @@ impl ImageCache {

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

ImageCacheTask::new(ipc_command_sender)
}

@@ -44,7 +44,7 @@ fn byte_swap_and_premultiply(data: &mut [u8]) {
}

pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
if buffer.len() == 0 {
if buffer.is_empty() {
return None;
}

@@ -120,5 +120,3 @@ fn is_gif(buffer: &[u8]) -> bool {
_ => false
}
}


@@ -83,7 +83,7 @@ impl LintPass for InheritancePass {
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,
"This DOM struct has no reflector or parent DOM struct");
}
@@ -232,7 +232,7 @@ impl CORSRequest {
_ => return error
};
// Substep 4
if methods.len() == 0 || preflight.mode == RequestMode::ForcedPreflight {
if methods.is_empty() || preflight.mode == RequestMode::ForcedPreflight {
methods = &methods_substep4;
}
// Substep 5
@@ -50,7 +50,7 @@ impl ByteString {
/// [RFC 2616](http://tools.ietf.org/html/rfc2616#page-17).
pub fn is_token(&self) -> bool {
let ByteString(ref vec) = *self;
if vec.len() == 0 {
if vec.is_empty() {
return false; // A token must be at least a single character
}
vec.iter().all(|&x| {
@@ -970,7 +970,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
/// https://html.spec.whatwg.org/multipage/#dom-window-cancelanimationframe
fn cancel_animation_frame(self, ident: i32) {
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 = window.r();
let ConstellationChan(ref chan) = window.constellation_chan();
@@ -231,7 +231,7 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement {
}
// Step 4.
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;
}
// Step 5.
@@ -2135,7 +2135,7 @@ impl<'a> NodeMethods for &'a Node {
NodeTypeId::DocumentFragment |
NodeTypeId::Element(..) => {
// Step 1-2.
let node = if value.len() == 0 {
let node = if value.is_empty() {
None
} else {
let document = self.owner_doc();
@@ -497,7 +497,7 @@ impl<'a> XMLHttpRequestMethods for &'a XMLHttpRequest {
// Step 7
self.upload_complete.set(match extracted {
None => true,
Some (ref v) if v.len() == 0 => true,
Some (ref v) if v.is_empty() => true,
_ => false
});

@@ -121,14 +121,14 @@ pub enum LengthOrPercentageOrAuto {
/// Parses a length per HTML5 § 2.4.4.4. If unparseable, `Auto` is returned.
pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
value = value.trim_left_matches(WHITESPACE);
if value.len() == 0 {
if value.is_empty() {
return LengthOrPercentageOrAuto::Auto
}
if value.starts_with("+") {
value = &value[1..]
}
value = value.trim_left_matches('0');
if value.len() == 0 {
if value.is_empty() {
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.
pub fn parse_legacy_color(mut input: &str) -> Result<RGBA,()> {
// Steps 1 and 2.
if input.len() == 0 {
if input.is_empty() {
return Err(())
}

@@ -243,7 +243,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA,()> {
let mut input = new_input;

// Step 11.
while input.len() == 0 || (input.len() % 3) != 0 {
while input.is_empty() || (input.len() % 3) != 0 {
input.push(b'0')
}

@@ -35,7 +35,7 @@ impl<T: Ord + PartialOrd + PartialEq> BinarySearchMethods<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> {
if self.len() == 0 {
if self.is_empty() {
return None;
}

@@ -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 {
unsafe {
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();
// 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();
@@ -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) {
unsafe {
if smm.is_null() { return; }
if (*smm).len() == 0 { return; }
if (*smm).is_empty() { return; }
for (_, val) in (*smm).iter_mut() {
while let Some(cs) = (*val).pop() {
cef_string_userfree_utf16_free(cs);

0 comments on commit 9c11781

Please sign in to comment.
You can’t perform that action at this time.