From: Peter Rabbitson Date: Mon, 18 Mar 2013 06:33:23 +0000 (+0100) Subject: Another parser microoptimisation - lose nullability checks where possible X-Git-Tag: v0.08250~31^2~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5e6d06f41642ba24ec94fd9eff7d373fefe24f76;p=dbsrgits%2FDBIx-Class.git Another parser microoptimisation - lose nullability checks where possible --- diff --git a/lib/DBIx/Class/ResultSource/RowParser/Util.pm b/lib/DBIx/Class/ResultSource/RowParser/Util.pm index f80fd7d..7d8f6a7 100644 --- a/lib/DBIx/Class/ResultSource/RowParser/Util.pm +++ b/lib/DBIx/Class/ResultSource/RowParser/Util.pm @@ -152,8 +152,11 @@ sub assemble_collapsing_parser { my @idcol_args = $no_rowid_container ? ('', '') : ( ', %cur_row_ids', # only declare the variable if we'll use it join ("\n", map { - qq(\$cur_row_ids{$_} = defined(\$cur_row_data->[$_]) ? \$cur_row_data->[$_] : "\0NULL\xFF\$rows_pos\xFF$_\0";) - } sort { $a <=> $b } keys %{ $stats->{idcols_seen} } ) + # in case we prune - we will never hit these undefs + $args->{prune_null_branches} + ? qq(\$cur_row_ids{$_} = \$cur_row_data->[$_];) + : qq(\$cur_row_ids{$_} = defined(\$cur_row_data->[$_]) ? \$cur_row_data->[$_] : "\0NULL\xFF\$rows_pos\xFF$_\0";) + } sort { $a <=> $b } keys %{ $stats->{idcols_seen} } ), ); my $parser_src = sprintf (<<'EOS', @idcol_args, $top_node_key_assembler||'', $top_node_key, join( "\n", @{$data_assemblers||[]} ) ); @@ -173,7 +176,9 @@ sub assemble_collapsing_parser { ( $_[1] and $rows_pos = -1 and $_[1]->() ) ) ) { - # this code exists only when we are *not* assembling direct to HRI + # this code exists only when we are using a cur_row_ids + # furthermore the undef checks may or may not be there + # depending on whether we prune or not # # due to left joins some of the ids may be NULL/undef, and # won't play well when used as hash lookups diff --git a/t/resultset/rowparser_internals.t b/t/resultset/rowparser_internals.t index 848b3a7..146c036 100644 --- a/t/resultset/rowparser_internals.t +++ b/t/resultset/rowparser_internals.t @@ -684,11 +684,12 @@ is_same_src ( ( $_[1] and $rows_pos = -1 and $_[1]->() ) ) ) { - $cur_row_ids{0} = defined $cur_row_data->[0] ? $cur_row_data->[0] : "\0NULL\xFF$rows_pos\xFF0\0"; - $cur_row_ids{2} = defined $cur_row_data->[2] ? $cur_row_data->[2] : "\0NULL\xFF$rows_pos\xFF2\0"; - $cur_row_ids{3} = defined $cur_row_data->[3] ? $cur_row_data->[3] : "\0NULL\xFF$rows_pos\xFF3\0"; - $cur_row_ids{4} = defined $cur_row_data->[4] ? $cur_row_data->[4] : "\0NULL\xFF$rows_pos\xFF4\0"; - $cur_row_ids{8} = defined $cur_row_data->[8] ? $cur_row_data->[8] : "\0NULL\xFF$rows_pos\xFF8\0"; + # do not care about nullability here + $cur_row_ids{0} = $cur_row_data->[0]; + $cur_row_ids{2} = $cur_row_data->[2]; + $cur_row_ids{3} = $cur_row_data->[3]; + $cur_row_ids{4} = $cur_row_data->[4]; + $cur_row_ids{8} = $cur_row_data->[8]; # cache expensive set of ops in a non-existent rowid slot $cur_row_ids{10} = (