From b413b7ee8903d7a8630e7042908937cc5126ac98 Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Thu, 6 Oct 2011 02:31:36 +0200 Subject: [PATCH] Improve the calculation part and reuse the values we have from the diff hunks. --- src/IDF/Diff.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/IDF/Diff.php b/src/IDF/Diff.php index 8f10e7f..bfc273e 100644 --- a/src/IDF/Diff.php +++ b/src/IDF/Diff.php @@ -178,7 +178,6 @@ class IDF_Diff $cc = 1; $offsets = array(); $contents = array(); - $maxlinenum = 0; foreach ($file['chunks'] as $chunk) { foreach ($chunk as $line) { @@ -195,8 +194,6 @@ class IDF_Diff $content = Pluf_esc($content); $content = self::makeNonPrintableCharsVisible($content); $contents[] = sprintf('%s', $class, $pretty, $content); - - $maxlinenum = max($maxlinenum, max($left, $right)); } if (count($file['chunks']) > $cc) { $offsets[] = '......'; @@ -212,11 +209,23 @@ class IDF_Diff '' ."\n"; $rows = count($offsets); - $colwidth = (ceil(log10($maxlinenum)) + 1) * 10; + + list($added, $removed) = end($file['chunks_def']); + + $added = $added[0] + $added[1]; + $leftwidth = 1; + if ($added > 0) + $leftwidth = (ceil(log10($added)) + 1) * 10; + + $removed = $removed[0] + $removed[1]; + $rightwidth = 1; + if ($removed > 0) + $rightwidth = (ceil(log10($removed)) + 1) * 10; + $first = array_shift($offsets); $out .= '' ."\n". - '' ."\n". + '' ."\n". ''. ''. '' ."\n".
'.Pluf_esc($filename).'