mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 21:19:24 +00:00
Use the standard 'new' operator.
This commit is contained in:
@@ -1,5 +1,14 @@
|
|||||||
2002-10-03 Bruno Haible <bruno@clisp.org>
|
2002-10-03 Bruno Haible <bruno@clisp.org>
|
||||||
|
|
||||||
|
* src/key-list.cc (Key_List::read_keys): Allocate the memory for the
|
||||||
|
hash table using 'new'.
|
||||||
|
(Key_List::output_lookup_array): Allocate the memory for the duplicates
|
||||||
|
array using 'new'.
|
||||||
|
* src/options.h (LARGE_STACK_ARRAYS): Remove definition.
|
||||||
|
* src/main.cc (main): Remove setrlimit call.
|
||||||
|
* src/configure.in: Don't test for unistd.h, sys/time.h,
|
||||||
|
sys/resource.h, getrlimit, setrlimit.
|
||||||
|
|
||||||
* src/bool-array.h (Bool_Array): Make all members non-static.
|
* src/bool-array.h (Bool_Array): Make all members non-static.
|
||||||
Add an argument to the constructor. Remove init(), rename reset() to
|
Add an argument to the constructor. Remove init(), rename reset() to
|
||||||
clear(), rename find() to set_bit().
|
clear(), rename find() to set_bit().
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
dnl autoconf configuration for gperf/src
|
dnl autoconf configuration for gperf/src
|
||||||
|
|
||||||
dnl Copyright (C) 1998, 2000 Free Software Foundation, Inc.
|
dnl Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc.
|
||||||
dnl written by Douglas C. Schmidt (schmidt@ics.uci.edu)
|
dnl written by Douglas C. Schmidt (schmidt@ics.uci.edu)
|
||||||
dnl
|
dnl
|
||||||
dnl This file is part of GNU GPERF.
|
dnl This file is part of GNU GPERF.
|
||||||
@@ -42,16 +42,6 @@ dnl
|
|||||||
dnl
|
dnl
|
||||||
dnl checks for functions and declarations
|
dnl checks for functions and declarations
|
||||||
dnl
|
dnl
|
||||||
AC_CHECK_HEADERS(unistd.h sys/time.h sys/resource.h)
|
|
||||||
dnl DEFs HAVE_UNISTD_H, HAVE_SYS_TIME_H, HAVE_SYS_RESOURCE_H
|
|
||||||
if test $ac_cv_header_sys_resource_h = yes; then
|
|
||||||
AC_CHECK_FUNCS(getrlimit)
|
|
||||||
dnl DEFS HAVE_GETRLIMIT
|
|
||||||
if test $ac_cv_func_getrlimit = yes; then
|
|
||||||
AC_CHECK_FUNCS(setrlimit)
|
|
||||||
dnl DEFS HAVE_SETRLIMIT
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
dnl
|
dnl
|
||||||
dnl checks for libraries
|
dnl checks for libraries
|
||||||
dnl
|
dnl
|
||||||
|
|||||||
@@ -382,19 +382,8 @@ Key_List::read_keys (void)
|
|||||||
|
|
||||||
/* Hash table this number of times larger than keyword number. */
|
/* Hash table this number of times larger than keyword number. */
|
||||||
int table_size = (list_len = total_keys) * TABLE_MULTIPLE;
|
int table_size = (list_len = total_keys) * TABLE_MULTIPLE;
|
||||||
|
/* Table must be a power of 2 for the hash function scheme to work. */
|
||||||
#if LARGE_STACK_ARRAYS
|
List_Node **table = new List_Node*[POW (table_size)];
|
||||||
/* By allocating the memory here we save on dynamic allocation overhead.
|
|
||||||
Table must be a power of 2 for the hash function scheme to work. */
|
|
||||||
List_Node *table[POW (table_size)];
|
|
||||||
#else
|
|
||||||
// Note: we don't use new, because that invokes a custom operator new.
|
|
||||||
int malloc_size = POW (table_size) * sizeof(List_Node*);
|
|
||||||
if (malloc_size == 0) malloc_size = 1;
|
|
||||||
List_Node **table = (List_Node**)malloc(malloc_size);
|
|
||||||
if (table == NULL)
|
|
||||||
abort ();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Make large hash table for efficiency. */
|
/* Make large hash table for efficiency. */
|
||||||
Hash_Table found_link (table, table_size, option[NOLENGTH]);
|
Hash_Table found_link (table, table_size, option[NOLENGTH]);
|
||||||
@@ -436,9 +425,7 @@ Key_List::read_keys (void)
|
|||||||
min_key_len = temp->key_length;
|
min_key_len = temp->key_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !LARGE_STACK_ARRAYS
|
delete[] table;
|
||||||
free ((char *) table);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Exit program if links exists and option[DUP] not set, since we can't continue */
|
/* Exit program if links exists and option[DUP] not set, since we can't continue */
|
||||||
if (total_duplicates)
|
if (total_duplicates)
|
||||||
@@ -1338,18 +1325,8 @@ Key_List::output_lookup_array (void)
|
|||||||
int count; /* Number of consecutive duplicates at this index. */
|
int count; /* Number of consecutive duplicates at this index. */
|
||||||
};
|
};
|
||||||
|
|
||||||
#if LARGE_STACK_ARRAYS
|
duplicate_entry *duplicates = new duplicate_entry[total_duplicates];
|
||||||
duplicate_entry duplicates[total_duplicates];
|
int *lookup_array = new int[max_hash_value + 1 + 2*total_duplicates];
|
||||||
int lookup_array[max_hash_value + 1 + 2*total_duplicates];
|
|
||||||
#else
|
|
||||||
// Note: we don't use new, because that invokes a custom operator new.
|
|
||||||
duplicate_entry *duplicates = (duplicate_entry *)
|
|
||||||
malloc (total_duplicates * sizeof(duplicate_entry) + 1);
|
|
||||||
int *lookup_array = (int *)
|
|
||||||
malloc ((max_hash_value + 1 + 2*total_duplicates) * sizeof(int));
|
|
||||||
if (duplicates == NULL || lookup_array == NULL)
|
|
||||||
abort();
|
|
||||||
#endif
|
|
||||||
int lookup_array_size = max_hash_value + 1;
|
int lookup_array_size = max_hash_value + 1;
|
||||||
duplicate_entry *dup_ptr = &duplicates[0];
|
duplicate_entry *dup_ptr = &duplicates[0];
|
||||||
int *lookup_ptr = &lookup_array[max_hash_value + 1 + 2*total_duplicates];
|
int *lookup_ptr = &lookup_array[max_hash_value + 1 + 2*total_duplicates];
|
||||||
@@ -1486,10 +1463,8 @@ Key_List::output_lookup_array (void)
|
|||||||
}
|
}
|
||||||
printf ("\n%s };\n\n", indent);
|
printf ("\n%s };\n\n", indent);
|
||||||
|
|
||||||
#if !LARGE_STACK_ARRAYS
|
delete[] duplicates;
|
||||||
free ((char *) duplicates);
|
delete[] lookup_array;
|
||||||
free ((char *) lookup_array);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
src/main.cc
27
src/main.cc
@@ -21,20 +21,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
|
|||||||
/* Simple driver program for the Gen_Perf.hash function generator.
|
/* Simple driver program for the Gen_Perf.hash function generator.
|
||||||
Most of the hard work is done in class Gen_Perf and its class methods. */
|
Most of the hard work is done in class Gen_Perf and its class methods. */
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <sys/types.h>
|
|
||||||
#if LARGE_STACK_ARRAYS && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
|
|
||||||
#ifdef HAVE_SYS_TIME_H
|
|
||||||
#include <sys/time.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_UNISTD_H
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "gen-perf.h"
|
#include "gen-perf.h"
|
||||||
@@ -42,19 +28,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
|
|||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if LARGE_STACK_ARRAYS && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) && defined(RLIMIT_STACK)
|
|
||||||
/* Get rid of any avoidable limit on stack size. */
|
|
||||||
{
|
|
||||||
struct rlimit rlim;
|
|
||||||
if (getrlimit (RLIMIT_STACK, &rlim) == 0)
|
|
||||||
if (rlim.rlim_cur < rlim.rlim_max)
|
|
||||||
{
|
|
||||||
rlim.rlim_cur = rlim.rlim_max;
|
|
||||||
setrlimit (RLIMIT_STACK, &rlim);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* RLIMIT_STACK */
|
|
||||||
|
|
||||||
/* Sets the Options. */
|
/* Sets the Options. */
|
||||||
option (argc, argv);
|
option (argc, argv);
|
||||||
|
|
||||||
|
|||||||
@@ -131,17 +131,6 @@ private:
|
|||||||
/* Global option coordinator for the entire program. */
|
/* Global option coordinator for the entire program. */
|
||||||
extern Options option;
|
extern Options option;
|
||||||
|
|
||||||
/* Set to 1 if your want to stack-allocate some large arrays.
|
|
||||||
This requires compiler support for variable-size arrays on the stack
|
|
||||||
(not ANSI). */
|
|
||||||
#ifndef LARGE_STACK_ARRAYS
|
|
||||||
#if defined(__GNUG__) && !defined(__STRICT_ANSI__)
|
|
||||||
#define LARGE_STACK_ARRAYS 1
|
|
||||||
#else
|
|
||||||
#define LARGE_STACK_ARRAYS 0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __OPTIMIZE__
|
#ifdef __OPTIMIZE__
|
||||||
|
|
||||||
#define INLINE inline
|
#define INLINE inline
|
||||||
|
|||||||
Reference in New Issue
Block a user