-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
11 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -526,9 +526,9 @@ pub fn (mut re RE) replace_n(in_txt string, repl_str string, count int) string { | |
mut lst := re.find_all(in_txt) | ||
|
||
if count < 0 { // start from the right of the string | ||
lst = lst#[count * 2..] // limitate the number of substitions | ||
lst = unsafe { lst#[count * 2..] } // limitate the number of substitions | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
medvednikov
Member
|
||
} else if count > 0 { // start from the left of the string | ||
lst = lst#[..count * 2] // limitate the number of substitions | ||
lst = unsafe { lst#[..count * 2] } // limitate the number of substitions | ||
} else if count == 0 { // no replace | ||
return in_txt | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
vlib/v/checker/tests/slice_clone_notice.vv:4:13: notice: an implicit clone of the slice was done here | ||
2 | xs := [1, 2, 3, 4, 5, 6, 7, 8] | ||
3 | | ||
4 | mut s := xs[1..] | ||
| ~~~~~ | ||
5 | | ||
6 | s.sort(a > b) | ||
Details: vlib/v/checker/tests/slice_clone_notice.vv:4:13: details: To silence this notice, use either an explicit `a[..].clone()`, | ||
or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice. | ||
2 | xs := [1, 2, 3, 4, 5, 6, 7, 8] | ||
3 | | ||
4 | mut s := xs[1..] | ||
| ~~~~~ | ||
5 | | ||
6 | s.sort(a > b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
fn main() { | ||
xs := [1, 2, 3, 4, 5, 6, 7, 8] | ||
|
||
mut s := xs[1..] | ||
|
||
s.sort(a > b) | ||
|
||
println(s) | ||
assert s == [8, 7, 6, 5, 4, 3, 2] | ||
println(xs) | ||
assert xs == [1, 2, 3, 4, 5, 6, 7, 8] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
fn test_array_slice_assign() { | ||
xs := [1, 2, 3, 4, 5, 6, 7, 8] | ||
|
||
mut s := xs[1..].clone() | ||
|
||
s.sort(a > b) | ||
|
||
println(s) | ||
assert s == [8, 7, 6, 5, 4, 3, 2] | ||
println(xs) | ||
assert xs == [1, 2, 3, 4, 5, 6, 7, 8] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Why unsafe here?
#
is safe for definiton :/