From: Ben Pfaff Date: Sun, 13 Jul 2014 17:41:13 +0000 (-0700) Subject: table-select: Only cut headers into two if needed in table_select_slice(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=1d0b435ea6ca932d3e1c446db402ec41b9024ccd table-select: Only cut headers into two if needed in table_select_slice(). Until now, when including headers in the table it returns, table_select_slice() has always either returned the entire original table or a set of chunks: left header, selected body, right header. However, it is possible to do better when the selected body includes all the cells up to, say, the right header: then you only need a single chunk to include the body and the right header. Besides saving memory, this also has the advantage that, if a joined cell crosses between the body and the header, it is not cut into two pieces by chunking. It doesn't make too much sense to join a cell across body and header, but this still makes it easier to render better if someone does that. The testsuite includes a few tables that do join a cell across body and header. This commit improves the output for one and changes some ugly output to different ugly output for another. Additional changes in an upcoming commit fix the latter and some other tables too. --- diff --git a/src/output/table-select.c b/src/output/table-select.c index 00d0ee9931..5bbc8caa1e 100644 --- a/src/output/table-select.c +++ b/src/output/table-select.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011, 2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -94,24 +94,30 @@ table_select_slice (struct table *subtable, enum table_axis axis, { struct table *table; int rect[TABLE_N_AXES][2]; + bool h0, h1; - if (add_headers) + h0 = add_headers && subtable->h[axis][0] > 0; + if (h0 && z0 == subtable->h[axis][0]) { - if (z0 == subtable->h[axis][0] - && z1 == subtable->n[axis] - subtable->h[axis][1]) - return subtable; - - if (subtable->h[axis][0]) - table_ref (subtable); - if (subtable->h[axis][1]) - table_ref (subtable); + z0 = 0; + h0 = false; } - else + + h1 = add_headers && subtable->h[axis][1] > 0; + if (h1 && z1 == subtable->n[axis] - subtable->h[axis][1]) { - if (z0 == 0 && z1 == subtable->n[axis]) - return subtable; + z1 = subtable->n[axis]; + h1 = false; } + if (z0 == 0 && z1 == subtable->n[axis]) + return subtable; + + if (h0) + table_ref (subtable); + if (h1) + table_ref (subtable); + rect[TABLE_HORZ][0] = 0; rect[TABLE_VERT][0] = 0; rect[TABLE_HORZ][1] = subtable->n[TABLE_HORZ]; @@ -120,22 +126,18 @@ table_select_slice (struct table *subtable, enum table_axis axis, rect[axis][1] = z1; table = table_select (subtable, rect); - if (add_headers) - { - if (subtable->h[axis][0]) - table = table_paste ( - table_select_slice (subtable, axis, 0, subtable->h[axis][0], - false), - table, axis); - - if (subtable->h[axis][1]) - table = table_paste ( - table, - table_select_slice (subtable, axis, - subtable->n[axis] - subtable->h[axis][1], - subtable->n[axis], false), - axis); - } + if (h0) + table = table_paste ( + table_select_slice (subtable, axis, 0, subtable->h[axis][0], false), + table, axis); + + if (h1) + table = table_paste ( + table, + table_select_slice (subtable, axis, + subtable->n[axis] - subtable->h[axis][1], + subtable->n[axis], false), + axis); return table; } diff --git a/tests/output/render.at b/tests/output/render.at index 721c2cd481..4bc14d809b 100644 --- a/tests/output/render.at +++ b/tests/output/render.at @@ -743,7 +743,7 @@ AT_CHECK([render-test --width=10 input], [0], [dnl +-+u+-+-+ |A|v|B|E| +-+-+C+-+ -|K K|D|L| +|IJK|D|L| +-+-+-+M| |Q|RST|N| +-+---+-+ @@ -789,7 +789,7 @@ op|h|q| +-+-+r| |xyz|s| +-+-+-+ -|E|F H| +|E| F| +-+-+-+ |L|O|P| |M+-+-+