@@ -6,15 +6,14 @@ use std::{
66 collections:: VecDeque ,
77 hash:: Hash ,
88 ops:: { Bound , RangeBounds } ,
9- rc:: Rc ,
109} ;
1110
1211use crate :: Error ;
1312
1413#[ derive( Clone , Debug ) ]
1514pub ( crate ) enum Repr < ' a > {
1615 Light ( & ' a str ) ,
17- Full ( Rc < Vec < ( & ' a str , usize ) > > ) ,
16+ Full ( Vec < ( & ' a str , usize ) > ) ,
1817}
1918
2019/// A rope data structure.
@@ -43,13 +42,13 @@ impl<'a> Rope<'a> {
4342 match & mut self . repr {
4443 Repr :: Light ( s) => {
4544 let vec = Vec :: from_iter ( [ ( * s, 0 ) , ( value, s. len ( ) ) ] ) ;
46- self . repr = Repr :: Full ( Rc :: new ( vec) ) ;
45+ self . repr = Repr :: Full ( vec) ;
4746 }
4847 Repr :: Full ( data) => {
4948 let len = data
5049 . last ( )
5150 . map_or ( 0 , |( chunk, start_pos) | * start_pos + chunk. len ( ) ) ;
52- Rc :: make_mut ( data) . push ( ( value, len) ) ;
51+ data. push ( ( value, len) ) ;
5352 }
5453 }
5554 }
@@ -61,15 +60,15 @@ impl<'a> Rope<'a> {
6160 match ( & mut self . repr , value. repr ) {
6261 ( Repr :: Light ( s) , Repr :: Light ( other) ) => {
6362 let raw = Vec :: from_iter ( [ ( * s, 0 ) , ( other, s. len ( ) ) ] ) ;
64- self . repr = Repr :: Full ( Rc :: new ( raw) ) ;
63+ self . repr = Repr :: Full ( raw) ;
6564 }
6665 ( Repr :: Full ( s) , Repr :: Full ( other) ) => {
6766 if !other. is_empty ( ) {
6867 let mut len = s
6968 . last ( )
7069 . map_or ( 0 , |( chunk, start_pos) | * start_pos + chunk. len ( ) ) ;
7170
72- let cur = Rc :: make_mut ( s ) ;
71+ let cur = s ;
7372 cur. reserve_exact ( other. len ( ) ) ;
7473
7574 for & ( chunk, _) in other. iter ( ) {
@@ -83,7 +82,7 @@ impl<'a> Rope<'a> {
8382 let len = s
8483 . last ( )
8584 . map_or ( 0 , |( chunk, start_pos) | * start_pos + chunk. len ( ) ) ;
86- Rc :: make_mut ( s ) . push ( ( other, len) ) ;
85+ s . push ( ( other, len) ) ;
8786 }
8887 }
8988 ( Repr :: Light ( s) , Repr :: Full ( other) ) => {
@@ -94,7 +93,7 @@ impl<'a> Rope<'a> {
9493 raw. push ( ( chunk, len) ) ;
9594 len += chunk. len ( ) ;
9695 }
97- self . repr = Repr :: Full ( Rc :: new ( raw) ) ;
96+ self . repr = Repr :: Full ( raw) ;
9897 }
9998 }
10099 }
@@ -325,7 +324,7 @@ impl<'a> Rope<'a> {
325324 } ) ?;
326325
327326 Ok ( Rope {
328- repr : Repr :: Full ( Rc :: new ( raw) ) ,
327+ repr : Repr :: Full ( raw) ,
329328 } )
330329 }
331330 }
@@ -413,7 +412,7 @@ impl<'a> Rope<'a> {
413412 } ) ;
414413
415414 Rope {
416- repr : Repr :: Full ( Rc :: new ( raw) ) ,
415+ repr : Repr :: Full ( raw) ,
417416 }
418417 }
419418 }
@@ -614,7 +613,7 @@ impl<'a> Iterator for Lines<'_, 'a> {
614613 // Advance the byte index to the end of the line.
615614 * byte_idx += len;
616615 Some ( Rope {
617- repr : Repr :: Full ( Rc :: new ( raw) ) ,
616+ repr : Repr :: Full ( raw) ,
618617 } )
619618 } else {
620619 // If we did not find a newline in the next few chunks,
@@ -646,7 +645,7 @@ impl<'a> Iterator for Lines<'_, 'a> {
646645 // Advance the byte index to the end of the rope.
647646 * byte_idx += len;
648647 Some ( Rope {
649- repr : Repr :: Full ( Rc :: new ( raw) ) ,
648+ repr : Repr :: Full ( raw) ,
650649 } )
651650 }
652651 }
@@ -864,7 +863,7 @@ impl<'a> FromIterator<&'a str> for Rope<'a> {
864863 . collect :: < Vec < _ > > ( ) ;
865864
866865 Self {
867- repr : Repr :: Full ( Rc :: new ( raw) ) ,
866+ repr : Repr :: Full ( raw) ,
868867 }
869868 }
870869}
@@ -889,8 +888,6 @@ fn end_bound_to_range_end(end: Bound<&usize>) -> Option<usize> {
889888
890889#[ cfg( test) ]
891890mod tests {
892- use std:: rc:: Rc ;
893-
894891 use crate :: rope:: { Repr , Rope } ;
895892
896893 impl < ' a > PartialEq for Repr < ' a > {
@@ -915,19 +912,19 @@ mod tests {
915912 assert_eq ! ( simple, "abcdef" ) ;
916913 assert_eq ! (
917914 simple. repr,
918- Repr :: Full ( Rc :: new ( Vec :: from_iter( [ ( "abc" , 0 ) , ( "def" , 3 ) ] ) ) )
915+ Repr :: Full ( Vec :: from_iter( [ ( "abc" , 0 ) , ( "def" , 3 ) ] ) )
919916 ) ;
920917 assert_eq ! ( simple. len( ) , 6 ) ;
921918
922919 simple. add ( "ghi" ) ;
923920 assert_eq ! ( simple, "abcdefghi" ) ;
924921 assert_eq ! (
925922 simple. repr,
926- Repr :: Full ( Rc :: new ( Vec :: from_iter( [
923+ Repr :: Full ( Vec :: from_iter( [
927924 ( "abc" , 0 ) ,
928925 ( "def" , 3 ) ,
929926 ( "ghi" , 6 ) ,
930- ] ) ) )
927+ ] ) )
931928 ) ;
932929 assert_eq ! ( simple. len( ) , 9 ) ;
933930 }
@@ -946,7 +943,7 @@ mod tests {
946943 assert_eq ! ( append1, "abcdef" ) ;
947944 assert_eq ! (
948945 append1. repr,
949- Repr :: Full ( Rc :: new ( Vec :: from_iter( [ ( "abc" , 0 ) , ( "def" , 3 ) , ] ) ) )
946+ Repr :: Full ( Vec :: from_iter( [ ( "abc" , 0 ) , ( "def" , 3 ) , ] ) )
950947 ) ;
951948
952949 // simple - complex
@@ -955,12 +952,12 @@ mod tests {
955952 assert_eq ! ( append2, "abc123" ) ;
956953 assert_eq ! (
957954 append2. repr,
958- Repr :: Full ( Rc :: new ( Vec :: from_iter( [
955+ Repr :: Full ( Vec :: from_iter( [
959956 ( "abc" , 0 ) ,
960957 ( "1" , 3 ) ,
961958 ( "2" , 4 ) ,
962959 ( "3" , 5 ) ,
963- ] ) ) )
960+ ] ) )
964961 ) ;
965962
966963 // complex - simple
@@ -969,12 +966,12 @@ mod tests {
969966 assert_eq ! ( append3, "123abc" ) ;
970967 assert_eq ! (
971968 append3. repr,
972- Repr :: Full ( Rc :: new ( Vec :: from_iter( [
969+ Repr :: Full ( Vec :: from_iter( [
973970 ( "1" , 0 ) ,
974971 ( "2" , 1 ) ,
975972 ( "3" , 2 ) ,
976973 ( "abc" , 3 ) ,
977- ] ) ) )
974+ ] ) )
978975 ) ;
979976
980977 // complex - complex
@@ -983,14 +980,14 @@ mod tests {
983980 assert_eq ! ( append4, "123456" ) ;
984981 assert_eq ! (
985982 append4. repr,
986- Repr :: Full ( Rc :: new ( Vec :: from_iter( [
983+ Repr :: Full ( Vec :: from_iter( [
987984 ( "1" , 0 ) ,
988985 ( "2" , 1 ) ,
989986 ( "3" , 2 ) ,
990987 ( "4" , 3 ) ,
991988 ( "5" , 4 ) ,
992989 ( "6" , 5 ) ,
993- ] ) ) )
990+ ] ) )
994991 ) ;
995992 }
996993
@@ -1071,7 +1068,7 @@ mod tests {
10711068 assert_eq ! ( rope, "abcdef" ) ;
10721069 assert_eq ! (
10731070 rope. repr,
1074- Repr :: Full ( Rc :: new ( Vec :: from_iter( [ ( "abc" , 0 ) , ( "def" , 3 ) ] ) ) )
1071+ Repr :: Full ( Vec :: from_iter( [ ( "abc" , 0 ) , ( "def" , 3 ) ] ) )
10751072 ) ;
10761073 }
10771074
0 commit comments