From owner-svn-src-user@FreeBSD.ORG Thu Aug 25 01:47:08 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EEA26106566B; Thu, 25 Aug 2011 01:47:08 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DECCB8FC08; Thu, 25 Aug 2011 01:47:08 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p7P1l8d9079281; Thu, 25 Aug 2011 01:47:08 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7P1l8Fj079279; Thu, 25 Aug 2011 01:47:08 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201108250147.p7P1l8Fj079279@svn.freebsd.org> From: Gabor Kovesdan Date: Thu, 25 Aug 2011 01:47:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225161 - user/gabor/tre-integration/contrib/tre/lib X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Aug 2011 01:47:09 -0000 Author: gabor Date: Thu Aug 25 01:47:08 2011 New Revision: 225161 URL: http://svn.freebsd.org/changeset/base/225161 Log: - Eliminate duplicated code snippet - Improve portability by eliminating FreeBSD-related dependencies Modified: user/gabor/tre-integration/contrib/tre/lib/hashtable.c Modified: user/gabor/tre-integration/contrib/tre/lib/hashtable.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/hashtable.c Thu Aug 25 01:00:54 2011 (r225160) +++ user/gabor/tre-integration/contrib/tre/lib/hashtable.c Thu Aug 25 01:47:08 2011 (r225161) @@ -24,14 +24,29 @@ * SUCH DAMAGE. */ -#include - #include #include #include #include "hashtable.h" + +/* + * Return a 32-bit hash of the given buffer. The init + * value should be 0, or the previous hash value to extend + * the previous hash. + */ +static uint32_t +hash32_buf(const void *buf, size_t len, uint32_t hash) +{ + const unsigned char *p = buf; + + while (len--) + hash = HASHSTEP(hash, *p++); + + return hash; +} + /* * Initializes a hash table that can hold table_size number of entries, * each of which has a key of key_size bytes and a value of value_size @@ -101,9 +116,6 @@ hashtable_put(hashtable *tbl, const void return (HASH_UPDATED); } - while (tbl->entries[hash] != NULL) - hash = (hash >= tbl->table_size) ? 0 : hash + 1; - tbl->entries[hash] = malloc(sizeof(hashtable_entry)); if (tbl->entries[hash] == NULL) {