Bug 1468544 - Replace mar_hash_name with CityHash algorithm. r=rstrong

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

Differential Revision: https://phabricator.services.mozilla.com/D10774
This commit is contained in:
June Wilde 2018-11-06 13:34:21 -05:00
Родитель 4b4a06a72b
Коммит 64fa52c710
4 изменённых файлов: 15 добавлений и 14 удалений

Просмотреть файл

@ -8,15 +8,10 @@
#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
@ -24,15 +19,8 @@
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,

Просмотреть файл

@ -24,6 +24,10 @@ UNIFIED_SOURCES += [
'mar_read.c',
]
LOCAL_INCLUDES += [
'../../../other-licenses/nsis/Contrib/CityHash/cityhash',
]
FORCE_STATIC_LIB = True
if CONFIG['OS_ARCH'] == 'WINNT':

Просмотреть файл

@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
HOST_SOURCES += [
'/other-licenses/nsis/Contrib/CityHash/cityhash/city.cpp',
'mar.c',
]
@ -58,4 +59,6 @@ if CONFIG['HOST_OS_ARCH'] == 'WINNT':
'ws2_32',
]
DisableStlWrapping()
HOST_DEFINES['NO_SIGN_VERIFY'] = True

Просмотреть файл

@ -50,6 +50,7 @@ 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.
@ -65,6 +66,8 @@ 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);
@ -78,6 +81,8 @@ uint64 CityHash64WithSeed(const char *buf, size_t len, uint64 seed);
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);
@ -97,5 +102,6 @@ inline uint64 Hash128to64(const uint128& x) {
b *= kMul;
return b;
}
#endif
#endif // CITY_HASH_H_