Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved decamelize performance
  • Loading branch information
kraih committed Sep 7, 2014
1 parent 11687a3 commit 75ac918
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

5.39 2014-09-06
5.39 2014-09-07
- Improved decamelize performance.
- Fixed bug in Mojo::Template where newline characters could get lost.

5.38 2014-09-05
Expand Down
17 changes: 5 additions & 12 deletions lib/Mojo/Util.pm
Expand Up @@ -70,7 +70,7 @@ sub camelize {

# CamelCase words
return join '::', map {
join '', map { ucfirst lc } split '_', $_
join('', map { ucfirst lc } split '_')
} split '-', $str;
}

Expand All @@ -87,17 +87,10 @@ sub decamelize {
my $str = shift;
return $str if $str !~ /^[A-Z]/;
# Module parts
my @parts;
for my $part (split '::', $str) {
# snake_case words
my @words;
push @words, lc $1 while $part =~ s/([A-Z]{1}[^A-Z]*)//;
push @parts, join '_', @words;
}
return join '-', @parts;
# snake_case words
return join '-', map {
join('_', map {lc} grep {length} split /([A-Z]{1}[^A-Z]*)/)
} split '::', $str;
}
sub decode {
Expand Down
4 changes: 2 additions & 2 deletions lib/Test/Mojo.pm
Expand Up @@ -433,8 +433,8 @@ L<Test::Mojo> implements the following attributes.
my $msg = $t->message;
$t = $t->message([text => $bytes]);
Current WebSocket message represented as an array reference containing
the frame type and payload.
Current WebSocket message represented as an array reference containing the
frame type and payload.
# Test custom message
$t->message([binary => $bytes])
Expand Down

0 comments on commit 75ac918

Please sign in to comment.