Commit Graph

56 Commits

Author SHA1 Message Date
Matt Mackall
776ce88bdd bdiff: fix pointer aliasing 2011-10-11 20:21:13 -05:00
Markus F.X.J. Oberhumer
159a87219b bdiff.c: rename all variables which hold a hash value to "hash" 2011-03-23 02:33:24 +01:00
Markus F.X.J. Oberhumer
b841bede91 bdiff.c: use unsigned arithmetic for hash computation
Signed integer overflow is undefined in C.
2011-03-23 02:33:23 +01:00
Markus F.X.J. Oberhumer
26bf54022b bdiff.c: cast to unsigned char when computing hash value 2011-03-23 02:33:22 +01:00
Markus F.X.J. Oberhumer
a68114a4d1 bdiff.c: make all local functions static 2011-03-23 02:33:21 +01:00
Martin Geisler
a76e121863 backout of e4cb9628354c
Matt and a majority of crew did not like this approach.
2011-01-27 11:15:08 +01:00
Martin Geisler
d23e1973c2 specify C indention style using Emacs file local variables 2011-01-26 12:05:01 +01:00
Matt Mackall
4b21988877 bdiff: Fix bogus NULL return 2010-12-06 16:59:43 -06:00
Matt Mackall
338e4487bf bdiff: dynamically allocate hunks
Make the hunk list a singly-linked list rather than a large array.
2010-12-06 16:42:48 -06:00
Renato Cunha
51519e8461 bdiff.c: Added support for py3k.
This patch adds support for py3k in bdiff.c. This is accomplished by including
a header file responsible for abstracting the API differences between python 2
and python 3.
2010-06-15 19:49:56 -03:00
Alistair Bell
fbefff7aa5 bdiff: do not use recursion / avoid stackoverflow (issue1940) 2010-02-18 10:32:51 +01:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Benoit Boissinot
3978618d04 bdiff: gradually enable the popularity hack
Patch from Jason Orendorff

The lower the threshold, the stronger the popularity hack's
influence. So at 3999 lines, the hack is disabled; and at 4000 lines,
the hack is enabled at maximum strength (t=4).

No source file in mercurial/crew is over 4000 lines. But there are, oh,
a few such files in Mozilla.  I can testify that this hack causes hg to
generate some correct but eyebrow-raising patches.

I think the hack should phase in gradually. The threshold should be high
for small files where we don't need it so much.  Like this:

        t = (bn < 31000) ? 1000000 / bn : bn / 1000;

That would leave the popularity hack disabled for small files, then
gradually phase it in:

    bn <   1000   --   t > bn    (popularity hack is completely disabled)
    bn ==  1000   --   t = 1000  (still effectively disabled)
    bn ==  2000   --   t =  500  (only hits unusual files)
    bn == 10000   --   t =  100  (only hits especially common lines)
    bn == 31000   --   t =   31  (hack is at maximum power)
    bn == 32000   --   t =   32  (hack could backfire, ease off)
2009-10-03 23:36:08 +02:00
Matt Mackall
9d8806e3c3 bdiff: fix compile with GCC -ansi (issue1690) 2009-06-20 11:50:51 -05:00
Benoit Boissinot
10822b7c00 bdiff: add comment about normalization 2009-01-12 17:51:57 +01:00
Dirkjan Ochtman
1c96ed002e merge with crew-stable, again 2008-10-20 14:58:49 +02:00
Thomas Arendsen Hein
380f8d8da9 spaces->tabs in one line of a C extension for consistency 2008-10-20 14:53:53 +02:00
Scott McCreary
501e6fe68f allow Mercurial to compile on Haiku 2008-09-17 10:22:35 +02:00
Benoit Boissinot
d6688cc959 bdiff: normalize the diff (issue1295)
When the common part of a diff can be moved forward, move it forward.
Otherwise we don't get deterministic results (it would depends on the way we
split for the recursion).
That way we get identical hunks when doing the same change, it helps to solve
issue1295 (inconsistent diffs on different side during a merge).
2008-10-14 20:13:53 +02:00
Jim Hague
b1341e30d4 fix calloc(0, ...) issue 2007-10-23 10:39:24 +00:00
Matt Mackall
0c1648fb37 bdiff: tweaks for large files
- adjust the common line threshold to .1%
  this speeds up a delta of 7M lines of source from 10m to 40s
- adjust the scaling of the hash array down a bit as it was raising the peak
  memory usage significantly
2007-10-11 00:46:56 -05:00
Matt Mackall
2a7d5cc815 bdiff: switch to lyhash
lyhash is a very simple and fast hash function that had the fewest
hash collisions on a 3.9M line text corpus and 190k line binary corpus
and should have significantly fewer collisions than the current hash
function.
2007-09-27 23:59:18 -05:00
Matt Mackall
4c16d712e6 bdiff: use INT_MAX to avoid some inner loop comparisons 2007-09-27 23:59:02 -05:00
Christoph Spiel
49d1dc563c bdiff: simple splitlines optimization 2007-09-27 23:58:54 -05:00
Christoph Spiel
52ef4eacce I have spotted the biggest bottleneck in "bdiff.c". Actually it was
pretty easy to find after I recompiled the python interpreter and
mercurial for profiling.

In "bdiff.c" function "equatelines" allocates the minimum hash table
size, which can lead to tons of collisions. I introduced an
"overcommit" factor of 16, this is, I allocate 16 times more memory
than the minimum value. Overcommiting 128 times does not improve the
performance over the 16-times case.
2007-09-27 23:57:57 -05:00
Alexis S. L. Carvalho
93eb041452 Merge with crew-stable 2007-03-04 09:03:21 -03:00
Erling Ellingsen
3c83c5579e don't return uninitialized memory from bdiff.blocks()
bdiff.blocks() returns a dummy match at the end of both files; the
length of that chunk is never set, so it will sometimes contain random
heap garbage. There are apparently workarounds for this elsewhere:

  # bdiff sometimes gives huge matches past eof, this check eats them,
2007-02-20 22:20:16 +01:00
Andrew Bachmann
3b2c3dac24 BeOS compatibility support 2007-01-02 21:40:20 -08:00
Benoit Boissinot
40a55ea6a3 add AIX to the list of compilers that don't have inline keyword 2006-10-27 10:24:19 +02:00
Alexis S. L. Carvalho
216a9bb3ee python2.5 PyArg_ParseTuple fix
Python 2.5 doesn't like it when we mix str objects and the "t#" format
in PyArg_ParseTuple. Change it to use "s#". Tested with python 2.3, 2.4
and 2.5.
2006-10-12 14:04:11 -03:00
Brendan Cully
65be154af0 Teach bdiff to support buffer objects
manifest.add gives revlog.addrevision a buffer object, which may
be cached and used for a second call in the same session (as mq does
when pushing multiple patches). The other option would be to cast the
buffer to str when caching it.
2006-10-11 12:06:14 -07:00
Vadim Gelfer
dc377b58c1 update copyrights. 2006-08-12 12:30:02 -07:00
Vadim Gelfer
e0b0ae3431 clean up trailing white space. 2006-07-12 08:28:00 -07:00
Vadim Gelfer
8c133566b8 bdiff: improve worst case behavior by 100x.
on 5.8MB (244.000 lines) text file with similar lines, hash before
this change made diff against empty file take 75 seconds.  this change
improves performance to 0.6 seconds.  result is that clone of smallish
repo (137MB) with some files like this takes 1 minute instead of 10
minutes.

common case of diff is 10% slower now, probably because of worse cache
locality. but diff does not affect overall performance in common case
(less than 1% of runtime is in diff when it is working ok), so this
tradeoff looks good.
2006-07-07 15:02:55 -07:00
Thomas Arendsen Hein
5088fdd568 Include inttypes.h instead of stdint.h (fixes issue299)
Many projects use inttypes.h, too. stdint.h isn't available everywhere, e.g.
on some versions of Solaris, while inttypes.h is available everywhere where
stdint.h is.
2006-06-30 21:41:46 +02:00
Shun-ichi GOTO
13b2a0288b Fixed conditional include of stdint.h for windows/msvc6/python2.3 environment. 2006-06-22 13:19:52 +09:00
Vadim Gelfer
e18ca75a83 mac os x: fixes for 10.2 from chris monson <monpublic@gmail.com> 2006-06-20 17:51:39 -07:00
TK Soh
9681381233 do proper typecasting on malloc() and calloc() calls
to support build on Solaris 2.6 using Sun Pro SC4.0 (C++ 4.1) compiler.
2006-03-20 08:46:29 +01:00
Fabian Otto
bfceaf2339 Sunpro compiler patch
The compiling runs through without warning, but runnig the newly builded
hg emmits a message:

| ImportError: ld.so.1: python: fatal: relocation error:
| file /opt/local/lib/python2.3/site-packages/mercurial/bdiff.so:
| symbol cmp: referenced symbol not found

Removing the inline infront of cmp corrects this error message.
2006-02-20 15:58:04 -06:00
twaldmann@thinkmo.de
bcc2a91159 made C src formatting more consistent 2005-11-14 04:58:28 +02:00
Matt Mackall
383ad8c32f bdiff: change spurious __inline to inline 2005-10-18 12:11:23 -07:00
mpm@selenic.com
56f9aeaf2d Fix possible unitialized variable warnings 2005-08-20 01:29:04 -07:00
tksoh@users.sourceforge.net
57e34bb4fd Allow Mercurial to build on HP-UX 11
Temporary fix to allow Mercurial to build on HP-UX 11, as the C
compiler on HP-UX 11 doesn't support 'inline' qualifier. The
'__inline' qualifier seemed to be supported, but not without
first resolving other associated issues.
2005-08-13 12:41:00 -08:00
Wallace, Eric S
ac33b6df10 Fix array overflow bug in bdiff
I ran into a bug while importing a large repository into mercurial.
The diff algorithm does not allocate a big enough array of hunks
for some test cases. This results in memory corruption, and possibly,
as in my case, a seg fault.

You should be able to reproduce this problem with any case of more
than a few lines that follows this pattern:

a  b
=  =
1  1
   2
2  3
   4
3  5
   .
4  .
   .
5
.
.
.

I.e., "a" has blank lines on every other line that have been removed in
"b". In this case, the number of matching hunks is equal to the number
of lines in "b". This is more than ((an + bn)/4 + 2). I'm not sure what
motivates this formula, but when I changed it to the smaller of an or
bn (+ 1), it works.

[comment added by mpm]
2005-08-04 13:25:59 -08:00
mpm@selenic.com
eee2ab41c0 [PATCH] use <arpa/inet.h> instead of <netinet/in.h> for ntohl/htonl
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[PATCH] use <arpa/inet.h> instead of <netinet/in.h> for ntohl/htonl

From: Jed Davis <jdev@panix.com>

This fixes the Mac OS X build problem; hopefully it won't break any
other OSes, especially since SUSv3 says arpa/inet is the right header.
( http://www.opengroup.org/onlinepubs/009695399/functions/ntohl.html )

manifest hash: 2f06ff0cffefdb35e794131afcd1f34f9fdfa5cf
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCyEoFywK+sNU5EO8RAk6WAJ9v/pnr07zUXKM9EBQQGaKSZAlhxACdHrwS
XTLSL6pPGAwaRfExGF2A3DQ=
=Rtv9
-----END PGP SIGNATURE-----
2005-07-03 12:26:45 -08:00
mpm@selenic.com
68e36bb922 [PATCH] bdiff/mpatch under MSVC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[PATCH] bdiff/mpatch under MSVC

From: K Thananchayan <thananck@yahoo.com>

MSVC (6.0) environment does not have 'stdint.h' and does not provide
`inline' qualifier. The following patch is needed to make mecurial
installable under MSVC.

manifest hash: a5b64235acced16cb451faa698922559fec4e573
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCxPapywK+sNU5EO8RAmRnAKCt9cOASaIsYB6kNUDSIStR1DmY4gCgnXlL
Jf0nMmGEkoyXtB0eV+fLzJU=
=fKD5
-----END PGP SIGNATURE-----
2005-06-30 23:54:17 -08:00
mpm@selenic.com
a053dfbfab More fiddling with uint32_t includes for extensions
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

More fiddling with uint32_t includes for extensions

manifest hash: 1ad16a0262e9bd2769e32c13c7fd0c7b0cd7dde7
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCwS+/ywK+sNU5EO8RAhK1AKCtF/57nKCc1AU+l0sR74kHhY1NCwCfSvQK
QQc5i8abuGkFpU5VUBJt5XQ=
=H+CX
-----END PGP SIGNATURE-----
2005-06-28 03:08:47 -08:00
mpm@selenic.com
fad4970cee Remove stdint.h from mpatch and bdiff
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Remove stdint.h from mpatch and bdiff

It's only there for ntohl and htonl and should be pulled in by in.h.

manifest hash: 65954290279241ac92c9ce04c21cf1a3c9dd54e0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCwD8KywK+sNU5EO8RAhv2AJ40R/T72XK63IbeEFqMLSRJbRJWdACcDa9r
dOL9XpyYxR09REbAHw0JrlE=
=8wkZ
-----END PGP SIGNATURE-----
2005-06-27 10:01:46 -08:00
mpm@selenic.com
302feb06a6 Minor speed improvements for bdiff
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Minor speed improvements for bdiff

Consolidate the jpos/jlen arrays to improve cache locality.
Do the same for the hash head/length arrays.

manifest hash: e6d9ed36782741b1d6fcce8c2d00155a9540e81d
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCvzWxywK+sNU5EO8RAlTMAJ9+yl0dKIeWv4RegeLy7g6wcnoYwgCgk6la
ip6KEAyBb7ktsX14KyZ5+/s=
=utNJ
-----END PGP SIGNATURE-----
2005-06-26 15:09:37 -08:00
mpm@selenic.com
44ac4156e1 extensions: use stdint.h
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

extensions: use stdint.h

Not sure why I didn't do this the first time around. Hopefully still
builds everywhere.

manifest hash: 965582286a190728f8cc0dfb8e11ee56628a59a5
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCvfRgywK+sNU5EO8RAg9SAJ4/ZVpQZcDY5xovLDTZK2txEegEgwCdF2b+
lzSIP109qq8D+KIdUWsbEPc=
=+0Yy
-----END PGP SIGNATURE-----
2005-06-25 16:18:40 -08:00