MB-9376: Put the reduce function on the heap

Change-Id: Ibe5095c219ca0a17467aa1a96ac58266bc186c5a
Reviewed-on: http://review.couchbase.org/29618
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
speed up file merging

Our file merging is dominated by very heavy comparison function. I've
spotted that previous binary-heap-based implementation was doing log_2
N comparisons twice per record. First to put record into heap and
second to remove it from heap.

Because we're doing 16-way merge (and we don't anticipate it being
much wider), I thought that simple insert-sort maintained sorted
vector would beat it. Particularly removal of least element does no
comparisons (it does memmove instead, but on short array that's very
cheap). And insertion does binary search to find position and memmove
to "create hole" for insertion.

Experimental results confirmed my finding. Particularly building
primary key index of 15E6 elements took 606 seconds instead of 665
seconds.

I have to admit that I've expected far bigger speedup but I now see
that I much understimated N log N factor of internal sorting of file
chunks, where smaller scale index sorting takes most of it's time.

Change-Id: I6da02231096d5138d19f9b0bb9e9d8b8175a2440
Reviewed-on: http://review.couchbase.org/29393
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
don't perform for-effect work inside assert

Because assert can be compiled-away if NDEBUG is defined.

Change-Id: Ic38d9e2bca79667343d94d44e94350158d20bb47
Reviewed-on: http://review.couchbase.org/29394
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
delete-trailing-whitespace

Change-Id: I742c825213e5671ebb2ebbb8a584c321e92b60ba
Reviewed-on: http://review.couchbase.org/29643
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
speedup unicode comparison

Change-Id: I0cc715bb01aa7b5d52fa7815b11cac3fab67a2a8
Reviewed-on: http://review.couchbase.org/29644
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Use C style comments in header included from c

Change-Id: I34bd370f78c052245096ecd61da3ca72565664f4
Reviewed-on: http://review.couchbase.org/29915
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Fix warnings from ISO C90

Change-Id: I8c26849362986c7e692386d27d2a7518a56153b4
Reviewed-on: http://review.couchbase.org/29916
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Fix collation of UTF-8 strings

There were a few problems here after commit
12b7cc0dddec9203878a3f91ef4e11768c01b857:

1) The API ucnv_toUnicode expects the target and source pointer
   limits to be 1 past the last valid byte;

2) In compareUnicode we were overriding the original string lengths,
   which would make the call to compareUnicodeSlow on failure get
   wrong string lengths;

3) size_t is an unsigned type, so the error checking was not working
   because a size_t value is always >= 0

Change-Id: Ia427e730d558edc6de523ba72717f49fe153b50e
Reviewed-on: http://review.couchbase.org/29987
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Add v8 version detection to configure.ac

Detect if v8 version > 3.19 and define macro V8_POST_3_19_API

Change-Id: Id97e2516e0d06706b3cf5649dbd5743923eb9de3
Reviewed-on: http://review.couchbase.org/30003
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9482 Add support for V8 versions post 3.19

Some of the v8 APIs have changed and newer versions does not support
copyable persistence objects. This commit conditionally uses older API
or newer API based on a macro definition `V8_POST_3_19_API`.

Change-Id: I37f45e59e0ee676b2cc1ac973883667187f7e03e
Reviewed-on: http://review.couchbase.org/30002
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Pass ICU linker flags to testapp

After a system upgrade, I couldn't build/run the tests anymore.
The ICU linker flags that icu-config gives us need to be passed
explicity to the linker when building the testapp.

fdmanana 12:05:53 ~/git/hub/membase/couchstore2 (master)> make check
make  testapp
make[1]: Entering directory `/home/fdmanana/git/hub/membase/couchstore2'
  CC     tests/testapp-testapp.o
  CC     tests/testapp-file_merger_tests.o
  CC     tests/testapp-file_sorter_tests.o
  CC     tests/mapreduce/testapp-tests.o
  CC     tests/mapreduce/testapp-map.o
  CC     tests/mapreduce/testapp-reduce.o
  CC     tests/mapreduce/testapp-builtin.o
  CC     tests/views/testapp-tests.o
  CC     tests/views/testapp-collate_json_test.o
  CC     tests/views/testapp-index_headers.o
  CC     tests/views/testapp-bitmaps.o
  CC     tests/views/testapp-sorted_lists.o
  CC     tests/views/testapp-reductions.o
  CC     tests/views/testapp-keys.o
  CC     tests/views/testapp-values.o
  CC     tests/views/testapp-reducers.o
  CC     tests/views/testapp-spatial.o
  CCLD   testapp
./.libs/libcouchstore_tests.a(libcouchstore_tests_la-collate_json.o): In function `convertUTF8toUChar':
/home/fdmanana/git/hub/membase/couchstore2/src/views/collate_json.c:255: undefined reference to `ucnv_toUnicode_48'
/home/fdmanana/git/hub/membase/couchstore2/src/views/collate_json.c:231: undefined reference to `ucnv_open_48'
./.libs/libcouchstore_tests.a(libcouchstore_tests_la-collate_json.o): In function `compareUnicodeSlow':
/home/fdmanana/git/hub/membase/couchstore2/src/views/collate_json.c:204: undefined reference to `uiter_setUTF8_48'
/home/fdmanana/git/hub/membase/couchstore2/src/views/collate_json.c:205: undefined reference to `uiter_setUTF8_48'
/home/fdmanana/git/hub/membase/couchstore2/src/views/collate_json.c:207: undefined reference to `ucol_strcollIter_48'
/home/fdmanana/git/hub/membase/couchstore2/src/views/collate_json.c:194: undefined reference to `ucol_open_48'
./.libs/libcouchstore_tests.a(libcouchstore_tests_la-collate_json.o): In function `compareUnicode':
/home/fdmanana/git/hub/membase/couchstore2/src/views/collate_json.c:294: undefined reference to `ucol_strcoll_48'
/home/fdmanana/git/hub/membase/couchstore2/src/views/collate_json.c:271: undefined reference to `ucol_open_48'
collect2: ld returned 1 exit status
make[1]: *** [testapp] Error 1
make[1]: Leaving directory `/home/fdmanana/git/hub/membase/couchstore2'
make: *** [check-am] Error 2

Change-Id: I802a640c1a200ccec02c7656c490885465de1853
Reviewed-on: http://review.couchbase.org/30133
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Check for __GNUC__ instead of HAVE_VISIBILITY

Change-Id: I74848480d33ce14b50232b765e592c37ef370b53
Transition to CMake

Change-Id: Ia99b910a5ae9b90e559f395b736288937a81e01f