File tree 1 file changed +20
-12
lines changed
1 file changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -436,23 +436,31 @@ pub mod reader {
436
436
}
437
437
}
438
438
439
- pub fn tagged_docs < F > ( d : Doc , tg : usize , mut it : F ) -> bool where
439
+ pub fn tagged_docs < F > ( d : Doc , tg : usize , it : F ) -> bool where
440
440
F : FnMut ( Doc ) -> bool ,
441
441
{
442
- let mut pos = d. start ;
443
- while pos < d. end {
444
- let elt_tag = try_or ! ( tag_at( d. data, pos) , false ) ;
445
- let elt_size = try_or ! ( tag_len_at( d. data, elt_tag) , false ) ;
446
- pos = elt_size. next + elt_size. val ;
447
- if elt_tag. val == tg {
448
- let doc = Doc { data : d. data , start : elt_size. next ,
449
- end : pos } ;
450
- if !it ( doc) {
451
- return false ;
442
+ TaggedDocsIterator {
443
+ iter : docs ( d) ,
444
+ tag : tg,
445
+ } . all ( it)
446
+ }
447
+
448
+ pub struct TaggedDocsIterator < ' a > {
449
+ iter : DocsIterator < ' a > ,
450
+ tag : usize ,
451
+ }
452
+
453
+ impl < ' a > Iterator for TaggedDocsIterator < ' a > {
454
+ type Item = Doc < ' a > ;
455
+
456
+ fn next ( & mut self ) -> Option < Doc < ' a > > {
457
+ while let Some ( ( tag, doc) ) = self . iter . next ( ) {
458
+ if tag == self . tag {
459
+ return Some ( doc) ;
452
460
}
453
461
}
462
+ None
454
463
}
455
- return true ;
456
464
}
457
465
458
466
pub fn with_doc_data < T , F > ( d : Doc , f : F ) -> T where
You can’t perform that action at this time.
0 commit comments