-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add warning for potentially slow loops
When a for loop iterates over a range that goes from 0 (or some other constant) to `filesize` (or some other expression that uses `filesize`) it may be very slow for large files. A loop that iterates over every byte in the file is not a very good idea.
- Loading branch information
Showing
6 changed files
with
97 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
rule test_1 { condition: for any i in (0..filesize) : ( int32(i) == 0 ) } | ||
|
||
rule test_2 { condition: for any i in (0..filesize-1) : ( int32(i) == 0 ) } | ||
|
||
// No warning | ||
rule test_3 { condition: for any i in (filesize-10..filesize) : ( int32(i) == 0 ) } |
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 @@ | ||
warning[potentially_slow_loop]: potentially slow loop | ||
--> line:1:39 | ||
| | ||
1 | rule test_1 { condition: for any i in (0..filesize) : ( int32(i) == 0 ) } | ||
| ------------- this range can be very large | ||
| | ||
warning[potentially_slow_loop]: potentially slow loop | ||
--> line:3:39 | ||
| | ||
3 | rule test_2 { condition: for any i in (0..filesize-1) : ( int32(i) == 0 ) } | ||
| --------------- this range can be very large | ||
| |
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