From: Peter Rabbitson Date: Tue, 3 Mar 2015 23:06:47 +0000 (+0100) Subject: Rewrite collapsing parser while loop (mere op-level golf) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8e06d750f0970fad6ce207781c837ead659204b7;p=dbsrgits%2FDBIx-Class.git Rewrite collapsing parser while loop (mere op-level golf) --- diff --git a/lib/DBIx/Class/ResultSource/RowParser/Util.pm b/lib/DBIx/Class/ResultSource/RowParser/Util.pm index 702240f..cb760ff 100644 --- a/lib/DBIx/Class/ResultSource/RowParser/Util.pm +++ b/lib/DBIx/Class/ResultSource/RowParser/Util.pm @@ -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 diff --git a/t/resultset/rowparser_internals.t b/t/resultset/rowparser_internals.t index 637304f..7ec9f37 100644 --- a/t/resultset/rowparser_internals.t +++ b/t/resultset/rowparser_internals.t @@ -252,9 +252,17 @@ is_same_src ( my ($result_pos, @collapse_idx, $cur_row_data, %cur_row_ids); while ($cur_row_data = ( - ( $rows_pos >= 0 and $_[0][$rows_pos++] ) - || - ( $_[1] and $rows_pos = -1 and $_[1]->() ) + ( + $rows_pos >= 0 + and + ( + $_[0][$rows_pos++] + or + ( ($rows_pos = -1), undef ) + ) + ) + or + ( $_[1] and $_[1]->() ) ) ) { @cur_row_ids{0,1,3,4,5} = ( @@ -314,9 +322,17 @@ is_same_src ( my ($result_pos, @collapse_idx, $cur_row_data, %cur_row_ids); while ($cur_row_data = ( - ( $rows_pos >= 0 and $_[0][$rows_pos++] ) - || - ( $_[1] and $rows_pos = -1 and $_[1]->() ) + ( + $rows_pos >= 0 + and + ( + $_[0][$rows_pos++] + or + ( ($rows_pos = -1), undef ) + ) + ) + or + ( $_[1] and $_[1]->() ) ) ) { @cur_row_ids{0, 1, 3, 4, 5} = @{$cur_row_data}[0, 1, 3, 4, 5]; @@ -433,9 +449,17 @@ is_same_src ( my ($result_pos, @collapse_idx, $cur_row_data, %cur_row_ids); while ($cur_row_data = ( - ( $rows_pos >= 0 and $_[0][$rows_pos++] ) - || - ( $_[1] and $rows_pos = -1 and $_[1]->() ) + ( + $rows_pos >= 0 + and + ( + $_[0][$rows_pos++] + or + ( ($rows_pos = -1), undef ) + ) + ) + or + ( $_[1] and $_[1]->() ) ) ) { @cur_row_ids{0, 1, 5, 6, 8, 10} = ( @@ -502,9 +526,17 @@ is_same_src ( my ($result_pos, @collapse_idx, $cur_row_data, %cur_row_ids); while ($cur_row_data = ( - ( $rows_pos >= 0 and $_[0][$rows_pos++] ) - || - ( $_[1] and $rows_pos = -1 and $_[1]->() ) + ( + $rows_pos >= 0 + and + ( + $_[0][$rows_pos++] + or + ( ($rows_pos = -1), undef ) + ) + ) + or + ( $_[1] and $_[1]->() ) ) ) { @cur_row_ids{( 0, 1, 5, 6, 8, 10 )} = @{$cur_row_data}[( 0, 1, 5, 6, 8, 10 )]; @@ -618,9 +650,17 @@ is_same_src ( my ($result_pos, @collapse_idx, $cur_row_data, %cur_row_ids); while ($cur_row_data = ( - ( $rows_pos >= 0 and $_[0][$rows_pos++] ) - || - ( $_[1] and $rows_pos = -1 and $_[1]->() ) + ( + $rows_pos >= 0 + and + ( + $_[0][$rows_pos++] + or + ( ($rows_pos = -1), undef ) + ) + ) + or + ( $_[1] and $_[1]->() ) ) ) { @cur_row_ids{( 0, 2, 3, 4, 8 )} = ( @@ -690,9 +730,17 @@ is_same_src ( my ($result_pos, @collapse_idx, $cur_row_data, %cur_row_ids); while ($cur_row_data = ( - ( $rows_pos >= 0 and $_[0][$rows_pos++] ) - || - ( $_[1] and $rows_pos = -1 and $_[1]->() ) + ( + $rows_pos >= 0 + and + ( + $_[0][$rows_pos++] + or + ( ($rows_pos = -1), undef ) + ) + ) + or + ( $_[1] and $_[1]->() ) ) ) { # do not care about nullability here @@ -763,9 +811,17 @@ is_same_src ( my ($result_pos, @collapse_idx, $cur_row_data, %cur_row_ids ); while ($cur_row_data = ( - ( $rows_pos >= 0 and $_[0][$rows_pos++] ) + ( + $rows_pos >= 0 + and + ( + $_[0][$rows_pos++] + or + ( ($rows_pos = -1), undef ) + ) + ) or - ( $_[1] and $rows_pos = -1 and $_[1]->() ) + ( $_[1] and $_[1]->() ) ) ) { @cur_row_ids{0,1} = @{$cur_row_data}[0,1];