[geary/wip/713891-traversable: 4/12] Nixing the caching collection bit
- From: Charles Lindsay <clindsay src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/713891-traversable: 4/12] Nixing the caching collection bit
- Date: Thu, 12 Dec 2013 02:57:51 +0000 (UTC)
commit b7841d3c93c16f8e7a23bfe457cb38527528ef7f
Author: Charles Lindsay <chaz yorba org>
Date: Wed Dec 11 16:57:51 2013 -0800
Nixing the caching collection bit
Doesn't seem like we'll need it after all. Either you're iterating over
the thing only once, or you know what kind of collection you really
want.
src/engine/util/util-traversable.vala | 119 ---------------------------------
1 files changed, 0 insertions(+), 119 deletions(-)
---
diff --git a/src/engine/util/util-traversable.vala b/src/engine/util/util-traversable.vala
index 3d5be23..155eb9c 100644
--- a/src/engine/util/util-traversable.vala
+++ b/src/engine/util/util-traversable.vala
@@ -90,10 +90,6 @@ public class Iterable<G> : BaseObject {
return true;
}
- public Collection<G> to_collection(owned Gee.EqualDataFunc<G>? equal_func = null) {
- return new Collection<G>(i, equal_func);
- }
-
public Gee.Collection<G> add_all_to(Gee.Collection<G> c) {
while (i.next())
c.add(i get());
@@ -120,119 +116,4 @@ public class Iterable<G> : BaseObject {
}
}
-/**
- * A Collection that lazily gets and caches results from an existing Iterator.
- * Will iterate over the given Iterator at most once.
- */
-public class Collection<G> : Gee.AbstractCollection<G> {
- private class Iterator<G> : BaseObject, Gee.Iterator<G>, Gee.Traversable<G> {
- private Collection<G> collection;
- private int cache_index = -1;
-
- public virtual bool valid { get { return cache_index >= 0; } }
- public virtual bool read_only { get { return true; } }
-
- public Iterator(Collection<G> collection) {
- this.collection = collection;
- }
-
- private void warn_read_only() {
- warning("%s is read-only", get_type().name());
- }
-
- public virtual bool next() {
- bool _has_next = has_next();
- if (_has_next)
- ++cache_index;
- return _has_next;
- }
-
- public virtual bool has_next() {
- if (cache_index + 1 >= collection.cache.size)
- return collection.cache_next();
- return true;
- }
-
- public new virtual G @get() {
- return collection cache get(cache_index);
- }
-
- public virtual void remove() {
- warn_read_only();
- }
-
- // For Gee.Traversable.
- public virtual bool @foreach(Gee.ForallFunc<G> f) {
- foreach (G item in collection) {
- if (!f(item))
- return false;
- }
- return true;
- }
- }
-
- private Gee.Iterator<G> source;
- private Gee.ArrayList<G> cache;
-
- public override int size { get { cache_all(); return cache.size; } }
- public override bool read_only { get { return true; } }
-
- public Collection(Gee.Iterator<G> iterator, owned Gee.EqualDataFunc<G>? equal_func = null) {
- base();
-
- source = iterator;
- cache = new Gee.ArrayList<G>((owned) equal_func);
- }
-
- private bool cache_next(out G element = null) {
- if (source.next()) {
- cache.add(element = source get());
- return true;
- }
- element = null;
- return false;
- }
-
- private void cache_all() {
- while (cache_next()) {
- // Nothing.
- }
- }
-
- private void warn_read_only() {
- warning("%s is read-only", get_type().name());
- }
-
- public override bool contains(G item) {
- if (cache.contains(item))
- return true;
-
- G test;
- while (cache_next(out test)) {
- if (cache.equal_func(test, item))
- return true;
- }
-
- return false;
- }
-
- public override bool add(G item) {
- warn_read_only();
- return false;
- }
-
- public override bool remove(G item) {
- warn_read_only();
- return false;
- }
-
- public override void clear() {
- warn_read_only();
- }
-
- public override Gee.Iterator<G> iterator() {
- return new Iterator<G>(this);
- }
-}
-
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]