Bug 1468544 - Replace mar_hash_name with CityHash algorithm; r=rstrong
☠☠ backed out by c6591e46a90c ☠ ☠
authorJune Wilde <jewilde@mozilla.com>
Tue, 06 Nov 2018 20:35:32 +0200
changeset 444659 196dcfd11ce337df9f185d43f9e29c7eb5c787d8
parent 444658 c916195bb47df5590b2339af1af1ca87d42da846
child 444660 c6591e46a90c1c87b7e2fe0f1575534833cae1e7
push id109622
push userarchaeopteryx@coole-files.de
push dateTue, 06 Nov 2018 18:42:52 +0000
treeherdermozilla-inbound@196dcfd11ce3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs1468544
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1468544 - Replace mar_hash_name with CityHash algorithm; r=rstrong Summary: Make CityHash64, CityHash64WithSeed, and CityHash64WithSeeds usable from C code Remove unnecessary includes from mar_read.c as well Add DisableStlWrapping to mar tool's moz.build to fix linkage break when building in Windows with MSVC Reviewers: rstrong Reviewed By: rstrong Bug #: 1468544 Differential Revision: https://phabricator.services.mozilla.com/D10774
modules/libmar/src/mar_read.c
modules/libmar/src/moz.build
modules/libmar/tool/moz.build
other-licenses/nsis/Contrib/CityHash/cityhash/city.h
--- a/modules/libmar/src/mar_read.c
+++ b/modules/libmar/src/mar_read.c
@@ -3,41 +3,29 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <sys/types.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
+#include "city.h"
 #include "mar_private.h"
 #include "mar.h"
 
-#ifdef XP_WIN
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#endif
-
 /* This block must be at most 104 bytes.
    MAR channel name < 64 bytes, and product version < 32 bytes + 3 NULL
    terminator bytes. We only check for 96 though because we remove 8
    bytes above from the additionalBlockSize: We subtract
    sizeof(additionalBlockSize) and sizeof(additionalBlockID) */
 #define MAXADDITIONALBLOCKSIZE 96
 
-/* this is the same hash algorithm used by nsZipArchive.cpp */
 static uint32_t mar_hash_name(const char *name) {
-  uint32_t val = 0;
-  unsigned char* c;
-
-  for (c = (unsigned char *) name; *c; ++c)
-    val = val*37 + *c;
-
-  return val % TABLESIZE;
+  return CityHash64(name, strlen(name)) % TABLESIZE;
 }
 
 static int mar_insert_item(MarFile *mar, const char *name, int namelen,
                            uint32_t offset, uint32_t length, uint32_t flags) {
   MarItem *item, *root;
   uint32_t hash;
 
   item = (MarItem *) malloc(sizeof(MarItem) + namelen);
--- a/modules/libmar/src/moz.build
+++ b/modules/libmar/src/moz.build
@@ -19,12 +19,16 @@ HostLibrary('hostmar')
 Library('mar')
 
 UNIFIED_SOURCES += [
     'mar_create.c',
     'mar_extract.c',
     'mar_read.c',
 ]
 
+LOCAL_INCLUDES += [
+    '../../../other-licenses/nsis/Contrib/CityHash/cityhash',
+]
+
 FORCE_STATIC_LIB = True
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     USE_STATIC_LIBS = True
--- a/modules/libmar/tool/moz.build
+++ b/modules/libmar/tool/moz.build
@@ -1,15 +1,16 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 HOST_SOURCES += [
+    '/other-licenses/nsis/Contrib/CityHash/cityhash/city.cpp',
     'mar.c',
 ]
 
 HostProgram('mar')
 
 HOST_USE_LIBS += [
     'hostmar',
 ]
@@ -53,9 +54,11 @@ elif CONFIG['OS_ARCH'] == 'Darwin':
       '-framework Security',
     ]
 
 if CONFIG['HOST_OS_ARCH'] == 'WINNT':
     HOST_OS_LIBS += [
         'ws2_32',
     ]
 
+DisableStlWrapping()
+
 HOST_DEFINES['NO_SIGN_VERIFY'] = True
--- a/other-licenses/nsis/Contrib/CityHash/cityhash/city.h
+++ b/other-licenses/nsis/Contrib/CityHash/cityhash/city.h
@@ -45,44 +45,49 @@
 
 #include <stdlib.h>  // for size_t.
 #include <stdint.h>
 
 typedef uint8_t uint8;
 typedef uint32_t uint32;
 typedef uint64_t uint64;
 
+#ifdef __cplusplus
 // The standard <utility> header doesn't compile, apparently it conflicts
 // with... some Mozilla something or other. But all that's used from it
 // is std::pair, so we can just replace that with mozilla::Pair.
 #ifndef MOZILLA_CLIENT
 #include <utility>
 typedef std::pair<uint64, uint64> uint128;
 inline uint64 Uint128Low64(const uint128& x) { return x.first; }
 inline uint64 Uint128High64(const uint128& x) { return x.second; }
 #else
 #include "mozilla/Pair.h"
 typedef mozilla::Pair<uint64, uint64> uint128;
 inline uint64 Uint128Low64(const uint128& x) { return x.first(); }
 inline uint64 Uint128High64(const uint128& x) { return x.second(); }
 #endif
 
+extern "C" {
+#endif
 
 // Hash function for a byte array.
 uint64 CityHash64(const char *buf, size_t len);
 
 // Hash function for a byte array.  For convenience, a 64-bit seed is also
 // hashed into the result.
 uint64 CityHash64WithSeed(const char *buf, size_t len, uint64 seed);
 
 // Hash function for a byte array.  For convenience, two seeds are also
 // hashed into the result.
 uint64 CityHash64WithSeeds(const char *buf, size_t len,
                            uint64 seed0, uint64 seed1);
 
+#ifdef __cplusplus
+}
 // Hash function for a byte array.
 uint128 CityHash128(const char *s, size_t len);
 
 // Hash function for a byte array.  For convenience, a 128-bit seed is also
 // hashed into the result.
 uint128 CityHash128WithSeed(const char *s, size_t len, uint128 seed);
 
 // Hash 128 input bits down to 64 bits of output.
@@ -92,10 +97,11 @@ inline uint64 Hash128to64(const uint128&
   const uint64 kMul = 0x9ddfea08eb382d69;
   uint64 a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul;
   a ^= (a >> 47);
   uint64 b = (Uint128High64(x) ^ a) * kMul;
   b ^= (b >> 47);
   b *= kMul;
   return b;
 }
+#endif
 
 #endif  // CITY_HASH_H_