diff --git a/mps-interpreter/src/lang/filter.rs b/mps-interpreter/src/lang/filter.rs index 0585941..16b1e41 100644 --- a/mps-interpreter/src/lang/filter.rs +++ b/mps-interpreter/src/lang/filter.rs @@ -363,6 +363,18 @@ impl Iterator for MpsFilterStatement

{ } } } + + fn size_hint(&self) -> (usize, Option) { + match &self.iterable { + VariableOrOp::Variable(s) => self.context.as_ref() + .and_then(|x| x.variables.get_opt(s)) + .and_then(|x| match x { + MpsType::Op(op) => Some(op.size_hint()), + _ => None + }), + VariableOrOp::Op(op) => op.try_real_ref().map(|x| x.size_hint()).ok() + }.unwrap_or((0, None)) + } } pub struct MpsFilterStatementFactory< diff --git a/mps-interpreter/src/lang/filter_replace.rs b/mps-interpreter/src/lang/filter_replace.rs index 619c36f..18d6a8f 100644 --- a/mps-interpreter/src/lang/filter_replace.rs +++ b/mps-interpreter/src/lang/filter_replace.rs @@ -310,6 +310,18 @@ impl Iterator for MpsFilterReplaceStatement

None => None, } } + + fn size_hint(&self) -> (usize, Option) { + match &self.iterable { + VariableOrOp::Variable(s) => self.context.as_ref() + .and_then(|x| x.variables.get_opt(s)) + .and_then(|x| match x { + MpsType::Op(op) => Some(op.size_hint()), + _ => None + }), + VariableOrOp::Op(op) => op.try_real_ref().map(|x| x.size_hint()).ok() + }.unwrap_or((0, None)) + } } fn declare_or_replace_item( diff --git a/mps-interpreter/src/lang/sorter.rs b/mps-interpreter/src/lang/sorter.rs index c32a4d3..82bffdb 100644 --- a/mps-interpreter/src/lang/sorter.rs +++ b/mps-interpreter/src/lang/sorter.rs @@ -101,6 +101,10 @@ impl Iterator for MpsSortStatement { } self.item_cache.pop_front() } + + fn size_hint(&self) -> (usize, Option) { + self.iterable.try_real_ref().map(|x| x.size_hint()).unwrap_or((0, None)) + } } pub struct MpsSortStatementFactory + 'static> { diff --git a/mps-interpreter/src/lang/vocabulary/comment.rs b/mps-interpreter/src/lang/vocabulary/comment.rs index bd7ed63..02984b9 100644 --- a/mps-interpreter/src/lang/vocabulary/comment.rs +++ b/mps-interpreter/src/lang/vocabulary/comment.rs @@ -49,6 +49,10 @@ impl Iterator for CommentStatement { fn next(&mut self) -> Option { None } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } impl MpsOp for CommentStatement { diff --git a/mps-interpreter/src/lang/vocabulary/empty.rs b/mps-interpreter/src/lang/vocabulary/empty.rs index 2fcd9ec..2862d78 100644 --- a/mps-interpreter/src/lang/vocabulary/empty.rs +++ b/mps-interpreter/src/lang/vocabulary/empty.rs @@ -36,6 +36,10 @@ impl Iterator for EmptyStatement { fn next(&mut self) -> Option { None } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } impl MpsOp for EmptyStatement { diff --git a/mps-interpreter/src/lang/vocabulary/files.rs b/mps-interpreter/src/lang/vocabulary/files.rs index 1a73aa2..47b3a41 100644 --- a/mps-interpreter/src/lang/vocabulary/files.rs +++ b/mps-interpreter/src/lang/vocabulary/files.rs @@ -95,6 +95,10 @@ impl Iterator for FilesStatement { None => None, } } + + fn size_hint(&self) -> (usize, Option) { + self.file_iter.as_ref().map(|x| x.size_hint()).unwrap_or((0, None)) + } } impl MpsOp for FilesStatement { diff --git a/mps-interpreter/src/lang/vocabulary/repeat.rs b/mps-interpreter/src/lang/vocabulary/repeat.rs index 5afc6a0..e19535c 100644 --- a/mps-interpreter/src/lang/vocabulary/repeat.rs +++ b/mps-interpreter/src/lang/vocabulary/repeat.rs @@ -147,6 +147,15 @@ impl Iterator for RepeatStatement { } } } + + fn size_hint(&self) -> (usize, Option) { + if self.inner_done { + let len = (self.cache.len() * (self.repetitions + 1)) - self.cache_position; + (len, Some(len)) + } else { + (0, None) + } + } } impl MpsOp for RepeatStatement { diff --git a/mps-interpreter/src/lang/vocabulary/reset.rs b/mps-interpreter/src/lang/vocabulary/reset.rs index bc7fef1..2830223 100644 --- a/mps-interpreter/src/lang/vocabulary/reset.rs +++ b/mps-interpreter/src/lang/vocabulary/reset.rs @@ -51,6 +51,10 @@ impl Iterator for ResetStatement { } None } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } impl MpsOp for ResetStatement { diff --git a/mps-interpreter/src/lang/vocabulary/sql_init.rs b/mps-interpreter/src/lang/vocabulary/sql_init.rs index 8922567..1412004 100644 --- a/mps-interpreter/src/lang/vocabulary/sql_init.rs +++ b/mps-interpreter/src/lang/vocabulary/sql_init.rs @@ -55,6 +55,10 @@ impl Iterator for SqlInitStatement { Err(e) => Some(Err(e)), } } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } } impl MpsOp for SqlInitStatement { diff --git a/mps-interpreter/src/lang/vocabulary/sql_query.rs b/mps-interpreter/src/lang/vocabulary/sql_query.rs index dec1aa2..33bb085 100644 --- a/mps-interpreter/src/lang/vocabulary/sql_query.rs +++ b/mps-interpreter/src/lang/vocabulary/sql_query.rs @@ -108,6 +108,11 @@ impl Iterator for SqlStatement { } } } + + fn size_hint(&self) -> (usize, Option) { + let len = self.rows.as_ref().map(|x| x.len()); + (len.unwrap_or(0), len) + } } impl Display for SqlStatement { diff --git a/mps-interpreter/src/lang/vocabulary/sql_simple_query.rs b/mps-interpreter/src/lang/vocabulary/sql_simple_query.rs index 8b5a350..a0a4072 100644 --- a/mps-interpreter/src/lang/vocabulary/sql_simple_query.rs +++ b/mps-interpreter/src/lang/vocabulary/sql_simple_query.rs @@ -170,6 +170,11 @@ impl Iterator for SimpleSqlStatement { } } } + + fn size_hint(&self) -> (usize, Option) { + let len = self.rows.as_ref().map(|x| x.len()); + (len.unwrap_or(0), len) + } } impl Display for SimpleSqlStatement { diff --git a/mps-interpreter/src/lang/vocabulary/variable_assign.rs b/mps-interpreter/src/lang/vocabulary/variable_assign.rs index 0048ae6..89b1d1c 100644 --- a/mps-interpreter/src/lang/vocabulary/variable_assign.rs +++ b/mps-interpreter/src/lang/vocabulary/variable_assign.rs @@ -120,6 +120,10 @@ impl Iterator for AssignStatement { } } } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(1)) + } } impl MpsOp for AssignStatement {