Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 29, 2013
1 parent 219b4b1 commit bf092f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

4.64 2013-12-24
4.64 2013-12-29

4.63 2013-12-19
- Deprecated Mojolicious::secret in favor of Mojolicious::secrets.
Expand Down
15 changes: 4 additions & 11 deletions lib/Mojo/DOM.pm
Expand Up @@ -190,8 +190,7 @@ sub text_before {
my @nodes;
for my $n (_nodes($tree->[3])) {
last if $n eq $tree;
push @nodes, $n;
@nodes = () if $n->[0] eq 'tag';
@nodes = $n->[0] eq 'tag' ? () : (@nodes, $n);
}

return _text(\@nodes, 0, _trim($tree->[3], $trim));
Expand Down Expand Up @@ -267,22 +266,16 @@ sub _link {
}

sub _nodes {
return unless my $n = shift;
return @$n[_offset($n) .. $#$n];
return unless my $tree = shift;
return @$tree[_offset($tree) .. $#$tree];
}

sub _offset { $_[0][0] eq 'root' ? 1 : 4 }

sub _parent {
my ($parent, $child) = @_;

# Find parent offset for child
my $i = _offset($parent);
for my $n (@$parent[$i .. $#$parent]) {
last if $n == $child;
$i++;
}

$_ eq $child ? last : $i++ for @$parent[$i .. $#$parent];
return $i;
}

Expand Down

0 comments on commit bf092f8

Please sign in to comment.