[PATCH] diff: rewrite V4. -1633 bytes

Matheus Izvekov mizvekov at gmail.com
Mon Jan 18 02:44:08 UTC 2010


>From e862a7c8d14dd511478c3a1dbbe2d48118200501 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov <mizvekov at gmail.com>
Date: Mon, 18 Jan 2010 00:32:28 -0200
Subject: [PATCH] diff: rewrite V4. -1633 bytes

This is an almost complete rewrite of diff, and fixes various bugs, including:
* How -b and -w flags work.
* The exit status when -q flag is set.
* Context is always taken from old file, instead of a mix of both.
* Now -S flag behaves exactly how it does on gnu diff. It does not error
  out in case it would make the list empty.
* Fixes to a ton of memory leaks. No leaks that I am aware of now.
* Diff against directories does not care about trailing slashes, exactly like how gnu diff does it.

FEATURE_DIFF_MINIMAL and FEATURE_DIFF_BINARY are removed, because
disabling them was not giving enough savings to be worth it.

Printing of modification time after the filename is removed, as this feature was deemed frivolous.
There shouldn't be any compatibility issues with gnu diff, as date was displayed in a different format anyway.
Please address me with any concerns about this.

Performance is still worse than original diff, but by only ~40% worst case now.
Fix to excessive and redundant seeking was implemented, in a more economical and less invasive way than
how it was done in Denys' last patch.

Fixes were also commited against various problems with the directory handling code.
Now diff between linux sources 2.6.32.3 and 2.6.33-rc4 produces exactly the same output as the old diff code.

Getting more performance is going to cost code size, so I need a position about if this is good enough.

Signed-off-by: Matheus Izvekov <mizvekov at gmail.com>

function                                             old     new   delta
diffreg                                             1755    2886   +1131
diff_main                                            842    1179    +337
read_token                                             -     153    +153
open3_or_warn                                          -      44     +44
skip_dir                                               -      40     +40
line_compar                                            -      39     +39
open_or_warn_stdin                                     -      28     +28
open_or_warn                                           -      10     +10
fetch                                                233     243     +10
add_to_dirlist                                        65      61      -4
xfopen_stdin                                          15       -     -15
print_only                                            18       -     -18
bb_msg_invalid_arg                                    30       -     -30
fopen_or_warn                                         31       -     -31
skipline                                              32       -     -32
fopen_or_warn_stdin                                   37       -     -37
warn_opendir                                          40       -     -40
newcand                                               80       -     -80
asciifile                                             89       -     -89
.rodata                                             6561    6458    -103
print_status                                         182      77    -105
make_temp                                            148       -    -148
get_recursive_dirlist                                182       -    -182
files_differ                                         182       -    -182
sort                                                 214       -    -214
prepare                                              247       -    -247
change                                               302       -    -302
do_diff                                              404       -    -404
dump_unified_vec                                     439       -    -439
check                                                723       -    -723
------------------------------------------------------------------------------
(add/remove: 6/18 grow/shrink: 3/3 up/down: 1792/-3425)     Total: -1633 bytes
   text	   data	    bss	    dec	    hex	filename
  70891	    737	   8576	  80204	  1394c	busybox_old
  69237	    733	   8576	  78546	  132d2	busybox_unstripped
---
 editors/Config.in |   16 -
 editors/diff.c    | 1821 ++++++++++++++++++++---------------------------------
 2 files changed, 687 insertions(+), 1150 deletions(-)


More information about the busybox mailing list