X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource%2FRowParser%2FUtil.pm;h=6ef758903fe3871bae213cb3730f0a91b357c8b5;hb=821edc0964a64b9d20b7d02c4a738b87e806f32d;hp=702240f55ff3d4292d217b189a0300cfe6952561;hpb=970d8ca1623b53b25a356f54e05ab126ee8a7782;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/ResultSource/RowParser/Util.pm b/lib/DBIx/Class/ResultSource/RowParser/Util.pm index 702240f..6ef7589 100644 --- a/lib/DBIx/Class/ResultSource/RowParser/Util.pm +++ b/lib/DBIx/Class/ResultSource/RowParser/Util.pm @@ -133,7 +133,7 @@ sub assemble_collapsing_parser { $top_node_key = "{ \$cur_row_ids{$virtual_column_idx} }"; - $top_node_key_assembler = sprintf " \$cur_row_ids{%d} = ( %s ); ", + $top_node_key_assembler = sprintf "( \$cur_row_ids{%d} = (%s) ),", $virtual_column_idx, "\n" . join( "\n or\n", @path_parts, qq{"\0\$rows_pos\0"} ) ; @@ -155,16 +155,16 @@ sub assemble_collapsing_parser { %{ $stats->{idcols_seen} }, } }; - my $row_id_defs = sprintf "\@cur_row_ids{( %s )} = ( \n%s \n );", + my $row_id_defs = sprintf "( \@cur_row_ids{( %s )} = (\n%s\n ) ),", join (', ', @row_ids ), # in case we prune - we will never hit undefs/NULLs as pigeon-hole-criteria ( $args->{prune_null_branches} ? sprintf( '@{$cur_row_data}[( %s )]', join ', ', @row_ids ) : join (",\n", map { - my $quoted_null_val = qq( "\0NULL\xFF\${rows_pos}\xFF${_}\0" ); + my $quoted_null_val = qq("\0NULL\xFF\${rows_pos}\xFF${_}\0"); HAS_DOR - ? qq! ( \$cur_row_data->[$_] // $quoted_null_val ) ! - : qq! ( defined(\$cur_row_data->[$_]) ? \$cur_row_data->[$_] : $quoted_null_val ) ! + ? qq!( \$cur_row_data->[$_] // $quoted_null_val )! + : qq!( defined(\$cur_row_data->[$_]) ? \$cur_row_data->[$_] : $quoted_null_val )! } @row_ids) ) ; @@ -181,9 +181,25 @@ sub assemble_collapsing_parser { # array, since the collapsed prefetch is smaller by definition. # At the end we cut the leftovers away and move on. while ($cur_row_data = ( - ( $rows_pos >= 0 and $_[0][$rows_pos++] ) + ( + $rows_pos >= 0 + and + ( + $_[0][$rows_pos++] + or + # It may be tempting to drop the -1 and undef $rows_pos instead + # thus saving the >= comparison above as well + # However NULL-handlers and underdefined root markers both use + # $rows_pos as a last-resort-uniqueness marker (it either is + # monotonically increasing while we parse ->all, or is set at + # a steady -1 when we are dealing with a single root node). For + # the time being the complication of changing all callsites seems + # overkill, for what is going to be a very modest saving of ops + ( ($rows_pos = -1), undef ) + ) + ) or - ( $_[1] and $rows_pos = -1 and $_[1]->() ) + ( $_[1] and $_[1]->() ) ) ) { # the undef checks may or may not be there @@ -202,7 +218,7 @@ sub assemble_collapsing_parser { # is ordered properly) # as long as we have a result already and the next result is new we # return the pre-read data and bail -$_[1] and $result_pos and ! $collapse_idx[0]%3$s and (unshift @{$_[2]}, $cur_row_data) and last; +( $_[1] and $result_pos and ! $collapse_idx[0]%3$s and (unshift @{$_[2]}, $cur_row_data) and last ), # the rel assemblers %4$s @@ -255,7 +271,7 @@ sub __visit_infmap_collapse { my @src; if ($cur_node_idx == 0) { - push @src, sprintf( '%s %s $_[0][$result_pos++] = %s;', + push @src, sprintf( '( %s %s $_[0][$result_pos++] = %s ),', $node_idx_slot, (HAS_DOR ? '//=' : '||='), $me_struct || '{}', @@ -269,7 +285,7 @@ sub __visit_infmap_collapse { ); if ($args->{collapse_map}->{-is_single}) { - push @src, sprintf ( '%s %s %s%s;', + push @src, sprintf ( '( %s %s %s%s ),', $parent_attach_slot, (HAS_DOR ? '//=' : '||='), $node_idx_slot, @@ -277,7 +293,7 @@ sub __visit_infmap_collapse { ); } else { - push @src, sprintf('(! %s) and push @{%s}, %s%s;', + push @src, sprintf('( (! %s) and push @{%s}, %s%s ),', $node_idx_slot, $parent_attach_slot, $node_idx_slot, @@ -316,7 +332,7 @@ sub __visit_infmap_collapse { if ($args->{prune_null_branches}) { # start of wrap of the entire chain in a conditional - splice @src, $rel_src_pos, 0, sprintf "( ! defined %s )\n ? %s%s{%s} = %s\n : do {", + splice @src, $rel_src_pos, 0, sprintf "( ( ! defined %s )\n ? %s%s{%s} = %s\n : do {", "\$cur_row_data->[$first_distinct_child_idcol]", $node_idx_slot, $args->{hri_style} ? '' : '[1]', @@ -325,11 +341,11 @@ sub __visit_infmap_collapse { ; # end of wrap - push @src, '};' + push @src, '} ),' } else { - splice @src, $rel_src_pos + 1, 0, sprintf ( '(defined %s) or bless (%s[1]{%s}, %s);', + splice @src, $rel_src_pos + 1, 0, sprintf ( '( (defined %s) or bless (%s[1]{%s}, %s) ),', "\$cur_row_data->[$first_distinct_child_idcol]", $node_idx_slot, perlstring($rel),