@@ -621,8 +621,7 @@ enum NormalizationForm {
621621#[ deriving( Clone ) ]
622622struct NormalizationIterator < ' self > {
623623 priv kind : NormalizationForm ,
624- priv index : uint ,
625- priv string : & ' self str ,
624+ priv iter : CharIterator < ' self > ,
626625 priv buffer : ~[ ( char , u8 ) ] ,
627626 priv sorted : bool
628627}
@@ -650,16 +649,17 @@ impl<'self> Iterator<char> for NormalizationIterator<'self> {
650649 NFKD => char:: decompose_compatible
651650 } ;
652651
653- while !self . sorted && self . index < self . string . len ( ) {
654- let CharRange { ch, next} = self . string . char_range_at ( self . index ) ;
655- self . index = next;
656- do decomposer( ch) |d| {
657- let class = canonical_combining_class ( d) ;
658- if class == 0 && !self . sorted {
659- canonical_sort ( self . buffer ) ;
660- self . sorted = true ;
652+ if !self . sorted {
653+ for ch in self . iter {
654+ do decomposer ( ch) |d| {
655+ let class = canonical_combining_class ( d) ;
656+ if class == 0 && !self . sorted {
657+ canonical_sort ( self . buffer ) ;
658+ self . sorted = true ;
659+ }
660+ self . buffer . push ( ( d, class) ) ;
661661 }
662- self . buffer . push ( ( d , class ) ) ;
662+ if self . sorted { break }
663663 }
664664 }
665665
@@ -678,7 +678,10 @@ impl<'self> Iterator<char> for NormalizationIterator<'self> {
678678 }
679679 }
680680
681- fn size_hint ( & self ) -> ( uint , Option < uint > ) { ( self . string . len ( ) , None ) }
681+ fn size_hint ( & self ) -> ( uint , Option < uint > ) {
682+ let ( lower, _) = self . iter . size_hint ( ) ;
683+ ( lower, None )
684+ }
682685}
683686
684687/// Replace all occurrences of one string with another
@@ -1628,8 +1631,7 @@ impl<'self> StrSlice<'self> for &'self str {
16281631 /// Returns the string in Unicode Normalization Form D (canonical decomposition)
16291632 fn nfd_iter(&self) -> NormalizationIterator<'self> {
16301633 NormalizationIterator {
1631- index: 0,
1632- string: *self,
1634+ iter: self.iter(),
16331635 buffer: ~[],
16341636 sorted: false,
16351637 kind: NFD
@@ -1639,8 +1641,7 @@ impl<'self> StrSlice<'self> for &'self str {
16391641 /// Returns the string in Unicode Normalization Form KD (compatibility decomposition)
16401642 fn nfkd_iter(&self) -> NormalizationIterator<'self> {
16411643 NormalizationIterator {
1642- index: 0,
1643- string: *self,
1644+ iter: self.iter(),
16441645 buffer: ~[],
16451646 sorted: false,
16461647 kind: NFKD
0 commit comments