33
33
* * access to a character by index is logarithmic (linear in strings);
34
34
*/
35
35
36
- use core:: option;
37
36
use core:: prelude:: * ;
38
- use core:: str;
39
- use core:: uint;
40
- use core:: vec;
41
37
42
38
/// The type of ropes.
43
39
pub type Rope = node:: Root ;
@@ -215,8 +211,8 @@ pub fn bal(rope:Rope) -> Rope {
215
211
match ( rope) {
216
212
node:: Empty => return rope,
217
213
node:: Content ( x) => match ( node:: bal ( x) ) {
218
- option :: None => rope,
219
- option :: Some ( y) => node:: Content ( y)
214
+ None => rope,
215
+ Some ( y) => node:: Content ( y)
220
216
}
221
217
}
222
218
}
@@ -558,13 +554,7 @@ pub fn char_at(rope: Rope, pos: uint) -> char {
558
554
pub mod node {
559
555
use rope:: node;
560
556
561
- use core:: cast;
562
- use core:: char;
563
- use core:: option;
564
557
use core:: prelude:: * ;
565
- use core:: str;
566
- use core:: uint;
567
- use core:: vec;
568
558
569
559
/// Implementation of type `rope`
570
560
pub enum Root {
@@ -835,8 +825,8 @@ pub mod node {
835
825
let mut it = leaf_iterator:: start ( node) ;
836
826
loop {
837
827
match leaf_iterator:: next ( & mut it) {
838
- option :: None => break ,
839
- option :: Some ( x) => {
828
+ None => break ,
829
+ Some ( x) => {
840
830
//FIXME (#2744): Replace with memcpy or something similar
841
831
let local_buf: ~[ u8 ] = cast:: transmute ( * x. content ) ;
842
832
let mut i = x. byte_offset ;
@@ -885,24 +875,24 @@ pub mod node {
885
875
*
886
876
* # Return value
887
877
*
888
- * * `option:: None` if no transformation happened
889
- * * `option:: Some(x)` otherwise, in which case `x` has the same contents
878
+ * * `None` if no transformation happened
879
+ * * `Some(x)` otherwise, in which case `x` has the same contents
890
880
* as `node` bot lower height and/or fragmentation.
891
881
*/
892
882
pub fn bal ( node : @Node ) -> Option < @Node > {
893
- if height ( node) < hint_max_node_height { return option :: None ; }
883
+ if height ( node) < hint_max_node_height { return None ; }
894
884
//1. Gather all leaves as a forest
895
885
let mut forest = ~[ ] ;
896
886
let mut it = leaf_iterator:: start ( node) ;
897
887
loop {
898
888
match leaf_iterator:: next ( & mut it) {
899
- option :: None => break ,
900
- option :: Some ( x) => forest. push ( @Leaf ( x) )
889
+ None => break ,
890
+ Some ( x) => forest. push ( @Leaf ( x) )
901
891
}
902
892
}
903
893
//2. Rebuild tree from forest
904
894
let root = @* tree_from_forest_destructive ( forest) ;
905
- return option :: Some ( root) ;
895
+ return Some ( root) ;
906
896
907
897
}
908
898
@@ -1061,14 +1051,14 @@ pub mod node {
1061
1051
while result == 0 {
1062
1052
match ( char_iterator:: next ( & mut ita) , char_iterator:: next ( & mut itb) )
1063
1053
{
1064
- ( option :: None , option :: None ) => break ,
1065
- ( option :: Some ( chara) , option :: Some ( charb) ) => {
1066
- result = char :: cmp ( chara , charb) ;
1054
+ ( None , None ) => break ,
1055
+ ( Some ( chara) , Some ( charb) ) => {
1056
+ result = chara . cmp ( & charb) as int ;
1067
1057
}
1068
- ( option :: Some ( _) , _) => {
1058
+ ( Some ( _) , _) => {
1069
1059
result = 1 ;
1070
1060
}
1071
- ( _, option :: Some ( _) ) => {
1061
+ ( _, Some ( _) ) => {
1072
1062
result = -1 ;
1073
1063
}
1074
1064
}
@@ -1145,9 +1135,7 @@ pub mod node {
1145
1135
pub mod leaf_iterator {
1146
1136
use rope:: node:: { Concat , Leaf , Node , height} ;
1147
1137
1148
- use core:: option;
1149
1138
use core:: prelude:: * ;
1150
- use core:: vec;
1151
1139
1152
1140
pub struct T {
1153
1141
stack : ~[ @Node ] ,
@@ -1168,7 +1156,7 @@ pub mod node {
1168
1156
}
1169
1157
1170
1158
pub fn next ( it : & mut T ) -> Option < Leaf > {
1171
- if it. stackpos < 0 { return option :: None ; }
1159
+ if it. stackpos < 0 { return None ; }
1172
1160
loop {
1173
1161
let current = it. stack [ it. stackpos ] ;
1174
1162
it. stackpos -= 1 ;
@@ -1179,7 +1167,7 @@ pub mod node {
1179
1167
it. stackpos += 1 ;
1180
1168
it. stack [ it. stackpos ] = x. left ;
1181
1169
}
1182
- Leaf ( x) => return option :: Some ( x)
1170
+ Leaf ( x) => return Some ( x)
1183
1171
}
1184
1172
} ;
1185
1173
}
@@ -1189,9 +1177,7 @@ pub mod node {
1189
1177
use rope:: node:: { Leaf , Node } ;
1190
1178
use rope:: node:: leaf_iterator;
1191
1179
1192
- use core:: option;
1193
1180
use core:: prelude:: * ;
1194
- use core:: str;
1195
1181
1196
1182
pub struct T {
1197
1183
leaf_iterator : leaf_iterator:: T ,
@@ -1202,28 +1188,28 @@ pub mod node {
1202
1188
pub fn start ( node : @Node ) -> T {
1203
1189
T {
1204
1190
leaf_iterator : leaf_iterator:: start ( node) ,
1205
- leaf : option :: None ,
1191
+ leaf : None ,
1206
1192
leaf_byte_pos : 0 u,
1207
1193
}
1208
1194
}
1209
1195
1210
1196
pub fn empty ( ) -> T {
1211
1197
T {
1212
1198
leaf_iterator : leaf_iterator:: empty ( ) ,
1213
- leaf : option :: None ,
1199
+ leaf : None ,
1214
1200
leaf_byte_pos : 0 u,
1215
1201
}
1216
1202
}
1217
1203
1218
1204
pub fn next ( it : & mut T ) -> Option < char > {
1219
1205
loop {
1220
1206
match get_current_or_next_leaf ( it) {
1221
- option :: None => return option :: None ,
1222
- option :: Some ( _) => {
1207
+ None => return None ,
1208
+ Some ( _) => {
1223
1209
let next_char = get_next_char_in_leaf ( it) ;
1224
1210
match next_char {
1225
- option :: None => loop ,
1226
- option :: Some ( _) => return next_char
1211
+ None => loop ,
1212
+ Some ( _) => return next_char
1227
1213
}
1228
1214
}
1229
1215
}
@@ -1232,12 +1218,12 @@ pub mod node {
1232
1218
1233
1219
pub fn get_current_or_next_leaf ( it : & mut T ) -> Option < Leaf > {
1234
1220
match it. leaf {
1235
- option :: Some ( _) => return it. leaf ,
1236
- option :: None => {
1221
+ Some ( _) => return it. leaf ,
1222
+ None => {
1237
1223
let next = leaf_iterator:: next ( & mut it. leaf_iterator ) ;
1238
1224
match next {
1239
- option :: None => return option :: None ,
1240
- option :: Some ( _) => {
1225
+ None => return None ,
1226
+ Some ( _) => {
1241
1227
it. leaf = next;
1242
1228
it. leaf_byte_pos = 0 u;
1243
1229
return next;
@@ -1249,20 +1235,20 @@ pub mod node {
1249
1235
1250
1236
pub fn get_next_char_in_leaf ( it : & mut T ) -> Option < char > {
1251
1237
match copy it. leaf {
1252
- option :: None => return option :: None ,
1253
- option :: Some ( aleaf) => {
1238
+ None => return None ,
1239
+ Some ( aleaf) => {
1254
1240
if it. leaf_byte_pos >= aleaf. byte_len {
1255
1241
//We are actually past the end of the leaf
1256
- it. leaf = option :: None ;
1257
- return option :: None
1242
+ it. leaf = None ;
1243
+ return None
1258
1244
} else {
1259
1245
let range =
1260
1246
str:: char_range_at ( * aleaf. content ,
1261
1247
( * it) . leaf_byte_pos + aleaf. byte_offset ) ;
1262
1248
let ch = range. ch ;
1263
1249
let next = range. next ;
1264
1250
( * it) . leaf_byte_pos = next - aleaf. byte_offset ;
1265
- return option :: Some ( ch)
1251
+ return Some ( ch)
1266
1252
}
1267
1253
}
1268
1254
}
@@ -1273,11 +1259,7 @@ pub mod node {
1273
1259
#[ cfg( test) ]
1274
1260
mod tests {
1275
1261
use rope:: * ;
1276
-
1277
- use core:: option;
1278
- use core:: str;
1279
- use core:: uint;
1280
- use core:: vec;
1262
+ use core:: prelude:: * ;
1281
1263
1282
1264
//Utility function, used for sanity check
1283
1265
fn rope_to_string ( r : Rope ) -> ~str {
@@ -1341,11 +1323,11 @@ mod tests {
1341
1323
let mut equal = true ;
1342
1324
while equal {
1343
1325
match ( node:: char_iterator:: next ( & mut rope_iter) ) {
1344
- option :: None => {
1326
+ None => {
1345
1327
if string_iter < string_len {
1346
1328
equal = false ;
1347
1329
} break ; }
1348
- option :: Some ( c) => {
1330
+ Some ( c) => {
1349
1331
let range = str:: char_range_at ( * sample, string_iter) ;
1350
1332
string_iter = range. next ;
1351
1333
if range. ch != c { equal = false ; break ; }
@@ -1373,8 +1355,8 @@ mod tests {
1373
1355
let mut it = iterator:: char:: start ( r) ;
1374
1356
loop {
1375
1357
match ( node:: char_iterator:: next ( & mut it) ) {
1376
- option :: None => break ,
1377
- option :: Some ( _) => len += 1 u
1358
+ None => break ,
1359
+ Some ( _) => len += 1 u
1378
1360
}
1379
1361
}
1380
1362
0 commit comments