Skip to content

Commit

Permalink
Replace uses of for foo in bar.iter(),
Browse files Browse the repository at this point in the history
and `for foo in bar.iter_mut(), and for foo in bar.into_iter()
(continuation of #7197)
  • Loading branch information
jxs committed Aug 18, 2015
1 parent f4b526c commit 067a22a
Show file tree
Hide file tree
Showing 32 changed files with 76 additions and 78 deletions.
20 changes: 10 additions & 10 deletions components/compositing/compositor.rs
Expand Up @@ -401,7 +401,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {

(Msg::AssignPaintedBuffers(pipeline_id, epoch, replies, frame_tree_id),
ShutdownState::NotShuttingDown) => {
for (layer_id, new_layer_buffer_set) in replies.into_iter() {
for (layer_id, new_layer_buffer_set) in replies {
self.assign_painted_buffers(pipeline_id,
layer_id,
new_layer_buffer_set,
Expand Down Expand Up @@ -1033,7 +1033,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn process_pending_scroll_events(&mut self) {
let had_scroll_events = self.pending_scroll_events.len() > 0;
for scroll_event in std_mem::replace(&mut self.pending_scroll_events,
Vec::new()).into_iter() {
Vec::new()) {
let delta = scroll_event.delta / self.scene.scale;
let cursor = scroll_event.cursor.as_f32() / self.scene.scale;

Expand Down Expand Up @@ -1073,7 +1073,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
.unwrap()
.push((extra_layer_data.id, visible_rect));

for kid in layer.children.borrow().iter() {
for kid in &*layer.children.borrow() {
process_layer(&*kid, window_size, new_display_ports)
}
}
Expand Down Expand Up @@ -1246,7 +1246,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
let scale = self.device_pixels_per_page_px();
let mut results: HashMap<PipelineId, Vec<PaintRequest>> = HashMap::new();

for (layer, mut layer_requests) in requests.into_iter() {
for (layer, mut layer_requests) in requests {
let pipeline_id = layer.pipeline_id();
let current_epoch = self.pipeline_details.get(&pipeline_id).unwrap().current_epoch;
layer.extra_data.borrow_mut().requested_epoch = current_epoch;
Expand Down Expand Up @@ -1293,7 +1293,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
pipeline.script_chan.send(ConstellationControlMsg::Viewport(pipeline.id.clone(), layer_rect)).unwrap();
}

for kid in layer.children().iter() {
for kid in &*layer.children() {
self.send_viewport_rect_for_layer(kid.clone());
}
}
Expand Down Expand Up @@ -1329,7 +1329,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
let pipeline_requests =
self.convert_buffer_requests_to_pipeline_requests_map(layers_and_requests);

for (pipeline_id, requests) in pipeline_requests.into_iter() {
for (pipeline_id, requests) in pipeline_requests {
let msg = ChromeToPaintMsg::Paint(requests, self.frame_tree_id);
let _ = self.get_pipeline(pipeline_id).chrome_to_paint_chan.send(msg);
}
Expand Down Expand Up @@ -1357,7 +1357,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
return true;
}

for child in layer.children().iter() {
for child in &*layer.children() {
if self.does_layer_have_outstanding_paint_messages(child) {
return true;
}
Expand Down Expand Up @@ -1659,7 +1659,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
*layer.bounds.borrow(),
*layer.masks_to_bounds.borrow(),
layer.establishes_3d_context);
for kid in layer.children().iter() {
for kid in &*layer.children() {
self.dump_layer_tree_with_indent(&**kid, level + 1)
}
}
Expand All @@ -1674,7 +1674,7 @@ fn find_layer_with_pipeline_and_layer_id_for_layer(layer: Rc<Layer<CompositorDat
return Some(layer);
}

for kid in layer.children().iter() {
for kid in &*layer.children() {
let result = find_layer_with_pipeline_and_layer_id_for_layer(kid.clone(),
pipeline_id,
layer_id);
Expand Down Expand Up @@ -1708,7 +1708,7 @@ impl<Window> CompositorEventListener for IOCompositor<Window> where Window: Wind
}

// Handle any messages coming from the windowing system.
for message in messages.into_iter() {
for message in messages {
self.handle_window_message(message);
}

Expand Down
16 changes: 8 additions & 8 deletions components/compositing/compositor_layer.rs
Expand Up @@ -250,7 +250,7 @@ impl CompositorLayer for Layer<CompositorData> {
compositor: &mut IOCompositor<Window>)
where Window: WindowMethods {
self.clear(compositor);
for kid in self.children().iter() {
for kid in &*self.children() {
kid.clear_all_tiles(compositor);
}
}
Expand All @@ -273,7 +273,7 @@ impl CompositorLayer for Layer<CompositorData> {
}
None => {
// Wasn't found, recurse into child layers
for kid in self.children().iter() {
for kid in &*self.children() {
kid.remove_root_layer_with_pipeline_id(compositor, pipeline_id);
}
}
Expand All @@ -288,7 +288,7 @@ impl CompositorLayer for Layer<CompositorData> {
// Traverse children first so that layers are removed
// bottom up - allowing each layer being removed to properly
// clean up any tiles it owns.
for kid in self.children().iter() {
for kid in &*self.children() {
kid.collect_old_layers(compositor, pipeline_id, new_layers);
}

Expand Down Expand Up @@ -324,12 +324,12 @@ impl CompositorLayer for Layer<CompositorData> {
/// This is used during shutdown, when we know the paint task is going away.
fn forget_all_tiles(&self) {
let tiles = self.collect_buffers();
for tile in tiles.into_iter() {
for tile in tiles {
let mut tile = tile;
tile.mark_wont_leak()
}

for kid in self.children().iter() {
for kid in &*self.children() {
kid.forget_all_tiles();
}
}
Expand All @@ -341,7 +341,7 @@ impl CompositorLayer for Layer<CompositorData> {
// Allow children to scroll.
let scroll_offset = self.extra_data.borrow().scroll_offset;
let new_cursor = cursor - scroll_offset;
for child in self.children().iter() {
for child in &*self.children() {
let child_bounds = child.bounds.borrow();
if child_bounds.contains(&new_cursor) {
let result = child.handle_scroll_event(delta, new_cursor - child_bounds.origin);
Expand Down Expand Up @@ -378,7 +378,7 @@ impl CompositorLayer for Layer<CompositorData> {
self.extra_data.borrow_mut().scroll_offset = new_offset;

let mut result = false;
for child in self.children().iter() {
for child in &*self.children() {
result |= child.scroll_layer_and_all_child_layers(new_offset);
}

Expand Down Expand Up @@ -429,7 +429,7 @@ impl CompositorLayer for Layer<CompositorData> {
}

let offset_for_children = new_offset + self.extra_data.borrow().scroll_offset;
for child in self.children().iter() {
for child in &*self.children() {
result |= child.scroll_layer_and_all_child_layers(offset_for_children);
}

Expand Down
2 changes: 1 addition & 1 deletion components/compositing/surface_map.rs
Expand Up @@ -69,7 +69,7 @@ impl SurfaceMap {
}

pub fn insert_surfaces(&mut self, display: &NativeDisplay, surfaces: Vec<NativeSurface>) {
for surface in surfaces.into_iter() {
for surface in surfaces {
self.insert(display, surface);
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/devtools/actor.rs
Expand Up @@ -150,7 +150,7 @@ impl ActorRegistry {
}

pub fn actor_to_script(&self, actor: String) -> String {
for (key, value) in self.script_actors.borrow().iter() {
for (key, value) in &*self.script_actors.borrow() {
println!("checking {}", value);
if *value == actor {
return key.to_string();
Expand Down Expand Up @@ -213,7 +213,7 @@ impl ActorRegistry {
}

let old_actors = replace(&mut *self.old_actors.borrow_mut(), vec!());
for name in old_actors.into_iter() {
for name in old_actors {
self.drop_actor(name);
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion components/devtools/lib.rs
Expand Up @@ -297,7 +297,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
columnNumber: console_message.columnNumber,
},
};
for stream in console_actor.streams.borrow_mut().iter_mut() {
for mut stream in &mut *console_actor.streams.borrow_mut() {
stream.write_json_packet(&msg);
}
}
Expand Down
12 changes: 6 additions & 6 deletions components/gfx/display_list/mod.rs
Expand Up @@ -340,7 +340,7 @@ impl StackingContext {
}

// Step 3: Positioned descendants with negative z-indices.
for positioned_kid in positioned_children.iter() {
for positioned_kid in &*positioned_children {
if positioned_kid.z_index >= 0 {
break
}
Expand Down Expand Up @@ -382,7 +382,7 @@ impl StackingContext {
}

// Step 9: Positioned descendants with nonnegative, numeric z-indices.
for positioned_kid in positioned_children.iter() {
for positioned_kid in &*positioned_children {
if positioned_kid.z_index < 0 {
continue
}
Expand Down Expand Up @@ -554,12 +554,12 @@ impl StackingContext {
// borders.
//
// TODO(pcwalton): Step 6: Inlines that generate stacking contexts.
for display_list in [
for display_list in &[
&self.display_list.positioned_content,
&self.display_list.content,
&self.display_list.floats,
&self.display_list.block_backgrounds_and_borders,
].iter() {
] {
hit_test_in_list(point, result, topmost_only, display_list.iter().rev());
if topmost_only && !result.is_empty() {
return
Expand Down Expand Up @@ -614,7 +614,7 @@ pub fn find_stacking_context_with_layer_id(this: &Arc<StackingContext>, layer_id
Some(_) | None => {}
}

for kid in this.display_list.children.iter() {
for kid in &this.display_list.children {
match find_stacking_context_with_layer_id(kid, layer_id) {
Some(stacking_context) => return Some(stacking_context),
None => {}
Expand Down Expand Up @@ -755,7 +755,7 @@ impl ClippingRegion {
#[inline]
pub fn bounding_rect(&self) -> Rect<Au> {
let mut rect = self.main;
for complex in self.complex.iter() {
for complex in &*self.complex {
rect = rect.union(&complex.rect)
}
rect
Expand Down
4 changes: 2 additions & 2 deletions components/gfx/paint_task.rs
Expand Up @@ -233,7 +233,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {

let mut replies = Vec::new();
for PaintRequest { buffer_requests, scale, layer_id, epoch, layer_kind }
in requests.into_iter() {
in requests {
if self.current_epoch == Some(epoch) {
self.paint(&mut replies, buffer_requests, scale, layer_id, layer_kind);
} else {
Expand Down Expand Up @@ -393,7 +393,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
}
};

for kid in stacking_context.display_list.children.iter() {
for kid in &stacking_context.display_list.children {
build(properties, &**kid, &page_position, &transform, &perspective, next_parent_id)
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/layout/animation.rs
Expand Up @@ -29,7 +29,7 @@ pub fn start_transitions_if_applicable(new_animations_sender: &Sender<Animation>
for i in 0..new_style.get_animation().transition_property.0.len() {
// Create any property animations, if applicable.
let property_animations = PropertyAnimation::from_transition(i, old_style, new_style);
for property_animation in property_animations.into_iter() {
for property_animation in property_animations {
// Set the property to the initial value.
property_animation.update(new_style, 0.0);

Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn process_new_animations(rw_data: &mut LayoutTaskData, pipeline_id: Pipelin
}

// Add new running animations.
for new_running_animation in new_running_animations.into_iter() {
for new_running_animation in new_running_animations {
match running_animations.entry(OpaqueNode(new_running_animation.node)) {
Entry::Vacant(entry) => {
entry.insert(vec![new_running_animation]);
Expand Down
8 changes: 4 additions & 4 deletions components/layout/construct.rs
Expand Up @@ -548,7 +548,7 @@ impl<'a> FlowConstructor<'a> {
fragments: successor_fragments,
})) => {
// Add any {ib} splits.
for split in splits.into_iter() {
for split in splits {
// Pull apart the {ib} split object and push its predecessor fragments
// onto the list.
let InlineBlockSplit {
Expand Down Expand Up @@ -722,7 +722,7 @@ impl<'a> FlowConstructor<'a> {

let mut style = (*style).clone();
properties::modify_style_for_text(&mut style);
for content_item in text_content.into_iter() {
for content_item in text_content {
let specific = match content_item {
ContentItem::String(string) => {
let info = UnscannedTextFragmentInfo::from_text(string);
Expand Down Expand Up @@ -765,7 +765,7 @@ impl<'a> FlowConstructor<'a> {
node: &ThreadSafeLayoutNode,
fragment_accumulator: &mut InlineFragmentsAccumulator,
opt_inline_block_splits: &mut LinkedList<InlineBlockSplit>) {
for split in splits.into_iter() {
for split in splits {
let InlineBlockSplit {
predecessors,
flow: kid_flow
Expand Down Expand Up @@ -1038,7 +1038,7 @@ impl<'a> FlowConstructor<'a> {
node: &ThreadSafeLayoutNode) {
let mut anonymous_flow = flow.generate_missing_child_flow(node);
let mut consecutive_siblings = vec!();
for kid_flow in child_flows.into_iter() {
for kid_flow in child_flows {
if anonymous_flow.need_anonymous_flow(&*kid_flow) {
consecutive_siblings.push(kid_flow);
continue;
Expand Down
2 changes: 1 addition & 1 deletion components/layout/flow.rs
Expand Up @@ -727,7 +727,7 @@ impl AbsoluteDescendants {
///
/// Ignore any static y offsets, because they are None before layout.
pub fn push_descendants(&mut self, given_descendants: AbsoluteDescendants) {
for elem in given_descendants.descendant_links.into_iter() {
for elem in given_descendants.descendant_links {
self.descendant_links.push(elem);
}
}
Expand Down
5 changes: 2 additions & 3 deletions components/layout/generated_content.rs
Expand Up @@ -277,11 +277,10 @@ impl<'a,'b> ResolveGeneratedContentFragmentMutator<'a,'b> {
self.traversal.counters.insert((*counter_name).clone(), counter);
}

for &(ref counter_name, value) in fragment.style()
for &(ref counter_name, value) in &fragment.style()
.get_counters()
.counter_increment
.0
.iter() {
.0 {
if let Some(ref mut counter) = self.traversal.counters.get_mut(counter_name) {
counter.increment(self.level, value);
continue
Expand Down
4 changes: 2 additions & 2 deletions components/layout/inline.rs
Expand Up @@ -1121,7 +1121,7 @@ impl InlineFlow {
let run = Arc::make_unique(&mut scanned_text_fragment_info.run);
{
let glyph_runs = Arc::make_unique(&mut run.glyphs);
for mut glyph_run in glyph_runs.iter_mut() {
for mut glyph_run in &mut *glyph_runs {
let mut range = glyph_run.range.intersect(&fragment_range);
if range.is_empty() {
continue
Expand Down Expand Up @@ -1226,7 +1226,7 @@ impl InlineFlow {
for frag in &self.fragments.fragments {
match frag.inline_context {
Some(ref inline_context) => {
for node in inline_context.nodes.iter() {
for node in &inline_context.nodes {
let font_style = node.style.get_font_arc();
let font_metrics = text::font_metrics_for_style(font_context, font_style);
let line_height = text::line_height_from_style(&*node.style, &font_metrics);
Expand Down
4 changes: 2 additions & 2 deletions components/layout/parallel.rs
Expand Up @@ -114,7 +114,7 @@ pub trait ParallelPreorderDomTraversal : PreorderDomTraversal {
top_down_func: ChunkedDomTraversalFunction,
bottom_up_func: DomTraversalFunction) {
let mut discovered_child_nodes = Vec::new();
for unsafe_node in unsafe_nodes.0.into_iter() {
for unsafe_node in *unsafe_nodes.0 {
// Get a real layout node.
let node: LayoutNode = unsafe {
layout_node_from_unsafe_layout_node(&unsafe_node)
Expand Down Expand Up @@ -295,7 +295,7 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
top_down_func: ChunkedFlowTraversalFunction,
bottom_up_func: FlowTraversalFunction) {
let mut discovered_child_flows = Vec::new();
for mut unsafe_flow in unsafe_flows.0.into_iter() {
for mut unsafe_flow in *unsafe_flows.0 {
let mut had_children = false;
unsafe {
// Get a real flow.
Expand Down
2 changes: 1 addition & 1 deletion components/net/image_cache_task.rs
Expand Up @@ -282,7 +282,7 @@ impl ImageCache {
let completed_load = CompletedLoad::new(image_response.clone());
self.completed_loads.insert(url, completed_load);

for listener in pending_load.listeners.into_iter() {
for listener in pending_load.listeners {
listener.notify(image_response.clone());
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/net/resource_task.rs
Expand Up @@ -212,7 +212,7 @@ impl ResourceManager {
fn set_cookies_for_url(&mut self, request: Url, cookie_list: String, source: CookieSource) {
let header = Header::parse_header(&[cookie_list.into_bytes()]);
if let Ok(SetCookie(cookies)) = header {
for bare_cookie in cookies.into_iter() {
for bare_cookie in cookies {
if let Some(cookie) = cookie::Cookie::new_wrapped(bare_cookie, &request, source) {
self.cookie_storage.push(cookie, source);
}
Expand Down

0 comments on commit 067a22a

Please sign in to comment.