Navigation Menu

Skip to content

Commit

Permalink
improved performance of contains method in Mojo::Asset::File by 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 10, 2012
1 parent 107c36e commit 721dbe9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

3.57 2012-11-10
- Improved performance of contains method in Mojo::Asset::File by 100%.
- Improved tests.
- Fixed range bug in Mojo::Asset::Memory.

Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/Asset/File.pm
Expand Up @@ -64,14 +64,14 @@ sub contains {
$handle->sysseek($self->start_range, SEEK_SET);

# Calculate window size
my $end = $self->end_range // $self->size;
my $size = length($string) * 2;
$size = $size > 131072 ? $size : 131072;
my $end = $self->end_range // $self->size;
my $len = length $string;
my $size = $len > 131072 ? $len : 131072;
$size = $end - $self->start_range if $size > $end - $self->start_range;

# Sliding window search
my $offset = 0;
my $start = $handle->sysread(my $window, $size);
my $start = $handle->sysread(my $window, $len);
while ($offset < $end) {

# Read as much as possible
Expand Down

0 comments on commit 721dbe9

Please sign in to comment.