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,6 +1,6 @@
|
||||
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
|
||||
dnl This file is part of GNU GPERF.
|
||||
@@ -42,16 +42,6 @@ dnl
|
||||
dnl
|
||||
dnl checks for functions and declarations
|
||||
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 checks for libraries
|
||||
dnl
|
||||
|
||||
@@ -382,19 +382,8 @@ Key_List::read_keys (void)
|
||||
|
||||
/* Hash table this number of times larger than keyword number. */
|
||||
int table_size = (list_len = total_keys) * TABLE_MULTIPLE;
|
||||
|
||||
#if LARGE_STACK_ARRAYS
|
||||
/* 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
|
||||
/* Table must be a power of 2 for the hash function scheme to work. */
|
||||
List_Node **table = new List_Node*[POW (table_size)];
|
||||
|
||||
/* Make large hash table for efficiency. */
|
||||
Hash_Table found_link (table, table_size, option[NOLENGTH]);
|
||||
@@ -436,9 +425,7 @@ Key_List::read_keys (void)
|
||||
min_key_len = temp->key_length;
|
||||
}
|
||||
|
||||
#if !LARGE_STACK_ARRAYS
|
||||
free ((char *) table);
|
||||
#endif
|
||||
delete[] table;
|
||||
|
||||
/* Exit program if links exists and option[DUP] not set, since we can't continue */
|
||||
if (total_duplicates)
|
||||
@@ -1338,18 +1325,8 @@ Key_List::output_lookup_array (void)
|
||||
int count; /* Number of consecutive duplicates at this index. */
|
||||
};
|
||||
|
||||
#if LARGE_STACK_ARRAYS
|
||||
duplicate_entry duplicates[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
|
||||
duplicate_entry *duplicates = new duplicate_entry[total_duplicates];
|
||||
int *lookup_array = new int[max_hash_value + 1 + 2*total_duplicates];
|
||||
int lookup_array_size = max_hash_value + 1;
|
||||
duplicate_entry *dup_ptr = &duplicates[0];
|
||||
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);
|
||||
|
||||
#if !LARGE_STACK_ARRAYS
|
||||
free ((char *) duplicates);
|
||||
free ((char *) lookup_array);
|
||||
#endif
|
||||
delete[] duplicates;
|
||||
delete[] lookup_array;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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.
|
||||
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 "options.h"
|
||||
#include "gen-perf.h"
|
||||
@@ -42,19 +28,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
|
||||
int
|
||||
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. */
|
||||
option (argc, argv);
|
||||
|
||||
|
||||
@@ -131,17 +131,6 @@ private:
|
||||
/* Global option coordinator for the entire program. */
|
||||
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__
|
||||
|
||||
#define INLINE inline
|
||||
|
||||
Reference in New Issue
Block a user