Skip to content

Commit c4580d2

Browse files
nunoplopeslucic71
authored andcommitted
simplify some string rules
1 parent 301a669 commit c4580d2

2 files changed

Lines changed: 72 additions & 68 deletions

File tree

tests/unit/out/refcount/string.rs

Lines changed: 71 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main_0() -> i32 {
4141
assert!((*s1.borrow())
4242
.iter()
4343
.copied()
44-
.take((*s1.borrow()).len() - 1)
44+
.take((*s1.borrow()).len().saturating_sub(1))
4545
.eq(Ptr::from_string_literal(b"hello").to_c_string_iterator()));
4646
let p1: Value<Ptr<u8>> = Rc::new(RefCell::new((s1.as_pointer() as Ptr<u8>)));
4747
assert!(((((*p1.borrow()).offset((0) as isize).read()) as i32) == (('h' as u8) as i32)));
@@ -98,8 +98,11 @@ fn main_0() -> i32 {
9898
(*i.borrow_mut()).prefix_inc();
9999
}
100100
let s3: Value<Vec<u8>> = Rc::new(RefCell::new({
101-
let mut __tmp1 = (*s2.borrow())
102-
[(2_u64) as usize..::std::cmp::min((2_u64 + 5_u64) as usize, (*s2.borrow()).len() - 1)]
101+
let mut __tmp1 = (*s2.borrow())[(2_u64) as usize
102+
..::std::cmp::min(
103+
(2_u64 + 5_u64) as usize,
104+
(*s2.borrow()).len().saturating_sub(1),
105+
)]
103106
.to_vec();
104107
__tmp1.push(0);
105108
__tmp1
@@ -120,20 +123,18 @@ fn main_0() -> i32 {
120123
let s4: Value<Vec<u8>> = Rc::new(RefCell::new({
121124
let mut __tmp1 = (*s1.borrow())[(1_u64) as usize
122125
..::std::cmp::min(
123-
(1_u64
124-
+ match (*s1.borrow())
126+
(1_u64 + {
127+
let __lookup: Vec<u8> = Ptr::from_string_literal(b"l")
128+
.to_c_string_iterator()
129+
.collect();
130+
(*s1.borrow())
125131
.iter()
126-
.take((*s1.borrow()).len() - 1)
127-
.rposition(|&x| {
128-
Ptr::from_string_literal(b"l")
129-
.to_c_string_iterator()
130-
.position(|ch| ch == x)
131-
.is_some()
132-
}) {
133-
Some(idx) => idx as u64,
134-
None => u64::MAX,
135-
}) as usize,
136-
(*s1.borrow()).len() - 1,
132+
.take((*s1.borrow()).len().saturating_sub(1))
133+
.rposition(|&x| __lookup.contains(&x))
134+
.map(|idx| idx as u64)
135+
.unwrap_or(u64::MAX)
136+
}) as usize,
137+
(*s1.borrow()).len().saturating_sub(1),
137138
)]
138139
.to_vec();
139140
__tmp1.push(0);
@@ -210,7 +211,7 @@ fn main_0() -> i32 {
210211
assert!((*string.borrow())
211212
.iter()
212213
.copied()
213-
.take((*string.borrow()).len() - 1)
214+
.take((*string.borrow()).len().saturating_sub(1))
214215
.eq(Ptr::from_string_literal(b"bar").to_c_string_iterator()));
215216
{
216217
(*string.borrow_mut()).pop();
@@ -239,7 +240,7 @@ fn main_0() -> i32 {
239240
assert!((*string.borrow())
240241
.iter()
241242
.copied()
242-
.take((*string.borrow()).len() - 1)
243+
.take((*string.borrow()).len().saturating_sub(1))
243244
.eq(Ptr::from_string_literal(b"bar").to_c_string_iterator()));
244245
{
245246
(*string.borrow_mut()).pop();
@@ -389,7 +390,10 @@ fn main_0() -> i32 {
389390
);
390391
let substr_0: Value<Vec<u8>> = Rc::new(RefCell::new({
391392
let mut __tmp1 = (*result.borrow())[(5_u64) as usize
392-
..::std::cmp::min((5_u64 + 3_u64) as usize, (*result.borrow()).len() - 1)]
393+
..::std::cmp::min(
394+
(5_u64 + 3_u64) as usize,
395+
(*result.borrow()).len().saturating_sub(1),
396+
)]
393397
.to_vec();
394398
__tmp1.push(0);
395399
__tmp1
@@ -415,7 +419,10 @@ fn main_0() -> i32 {
415419
);
416420
let substr_1: Value<Vec<u8>> = Rc::new(RefCell::new({
417421
let mut __tmp1 = (*result.borrow())[(0_u64) as usize
418-
..::std::cmp::min((0_u64 + 5_u64) as usize, (*result.borrow()).len() - 1)]
422+
..::std::cmp::min(
423+
(0_u64 + 5_u64) as usize,
424+
(*result.borrow()).len().saturating_sub(1),
425+
)]
419426
.to_vec();
420427
__tmp1.push(0);
421428
__tmp1
@@ -453,7 +460,10 @@ fn main_0() -> i32 {
453460
);
454461
let substr_2: Value<Vec<u8>> = Rc::new(RefCell::new({
455462
let mut __tmp1 = (*result.borrow())[(0_u64) as usize
456-
..::std::cmp::min((0_u64 + 15_u64) as usize, (*result.borrow()).len() - 1)]
463+
..::std::cmp::min(
464+
(0_u64 + 15_u64) as usize,
465+
(*result.borrow()).len().saturating_sub(1),
466+
)]
457467
.to_vec();
458468
__tmp1.push(0);
459469
__tmp1
@@ -507,58 +517,52 @@ fn main_0() -> i32 {
507517
.read()) as i32)
508518
== (('o' as u8) as i32))
509519
);
510-
let pos: Value<u64> = Rc::new(RefCell::new(
511-
match (*result.borrow())
520+
let pos: Value<u64> = Rc::new(RefCell::new({
521+
let __lookup: Vec<u8> = Ptr::from_string_literal(b"b")
522+
.to_c_string_iterator()
523+
.collect();
524+
(*result.borrow())
512525
.iter()
513-
.take((*result.borrow()).len() - 1)
514-
.rposition(|&x| {
515-
Ptr::from_string_literal(b"b")
516-
.to_c_string_iterator()
517-
.position(|ch| ch == x)
518-
.is_some()
519-
}) {
520-
Some(idx) => idx as u64,
521-
None => u64::MAX,
522-
},
523-
));
526+
.take((*result.borrow()).len().saturating_sub(1))
527+
.rposition(|&x| __lookup.contains(&x))
528+
.map(|idx| idx as u64)
529+
.unwrap_or(u64::MAX)
530+
}));
524531
assert!(((*pos.borrow()) == 0_u64));
525-
(*pos.borrow_mut()) = match (*result.borrow())
526-
.iter()
527-
.take((*result.borrow()).len() - 1)
528-
.rposition(|&x| {
529-
Ptr::from_string_literal(b"f")
530-
.to_c_string_iterator()
531-
.position(|ch| ch == x)
532-
.is_some()
533-
}) {
534-
Some(idx) => idx as u64,
535-
None => u64::MAX,
532+
(*pos.borrow_mut()) = {
533+
let __lookup: Vec<u8> = Ptr::from_string_literal(b"f")
534+
.to_c_string_iterator()
535+
.collect();
536+
(*result.borrow())
537+
.iter()
538+
.take((*result.borrow()).len().saturating_sub(1))
539+
.rposition(|&x| __lookup.contains(&x))
540+
.map(|idx| idx as u64)
541+
.unwrap_or(u64::MAX)
536542
};
537543
assert!(((*pos.borrow()) == 5_u64));
538-
(*pos.borrow_mut()) = match (*result.borrow())
539-
.iter()
540-
.take((*result.borrow()).len() - 1)
541-
.rposition(|&x| {
542-
Ptr::from_string_literal(b"o")
543-
.to_c_string_iterator()
544-
.position(|ch| ch == x)
545-
.is_some()
546-
}) {
547-
Some(idx) => idx as u64,
548-
None => u64::MAX,
544+
(*pos.borrow_mut()) = {
545+
let __lookup: Vec<u8> = Ptr::from_string_literal(b"o")
546+
.to_c_string_iterator()
547+
.collect();
548+
(*result.borrow())
549+
.iter()
550+
.take((*result.borrow()).len().saturating_sub(1))
551+
.rposition(|&x| __lookup.contains(&x))
552+
.map(|idx| idx as u64)
553+
.unwrap_or(u64::MAX)
549554
};
550555
assert!(((*pos.borrow()) == 7_u64));
551-
(*pos.borrow_mut()) = match (*result.borrow())
552-
.iter()
553-
.take((*result.borrow()).len() - 1)
554-
.rposition(|&x| {
555-
Ptr::from_string_literal(b"x")
556-
.to_c_string_iterator()
557-
.position(|ch| ch == x)
558-
.is_some()
559-
}) {
560-
Some(idx) => idx as u64,
561-
None => u64::MAX,
556+
(*pos.borrow_mut()) = {
557+
let __lookup: Vec<u8> = Ptr::from_string_literal(b"x")
558+
.to_c_string_iterator()
559+
.collect();
560+
(*result.borrow())
561+
.iter()
562+
.take((*result.borrow()).len().saturating_sub(1))
563+
.rposition(|&x| __lookup.contains(&x))
564+
.map(|idx| idx as u64)
565+
.unwrap_or(u64::MAX)
562566
};
563567
assert!(((*pos.borrow()) == (-1_i64 as u64)));
564568
let string_to_cast: Value<Vec<u8>> = Rc::new(RefCell::new(

tests/unit/out/refcount/string2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main_0() -> i32 {
2626
assert!((*arr.borrow())
2727
.iter()
2828
.copied()
29-
.take((*arr.borrow()).len() - 1)
29+
.take((*arr.borrow()).len().saturating_sub(1))
3030
.eq(Ptr::from_string_literal(b"fbo").to_c_string_iterator()));
3131
return 0;
3232
}

0 commit comments

Comments
 (0)