/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */ #include "String.hpp" #include "Hash.hpp" #include "Jam.hpp" /* * newstr.c - string manipulation routines * * To minimize string copying, string creation, copying, and freeing * is done through newstr. * * External functions: * * newstr() - return a malloc'ed copy of a string * copystr() - return a copy of a string previously returned by newstr() * freestr() - free a string returned by newstr() or copystr() * donestr() - free string tables * * Once a string is passed to newstr(), the returned string is readonly. * * This implementation builds a hash table of all strings, so that multiple * calls of newstr() on the same string allocate memory for the string once. * Strings are never actually freed. */ static struct hash *strhash = 0; static int strtotal = 0; namespace Jam { /* * newstr() - return a malloc'ed copy of a string */ char * String::newstr( const char *string ) { char* str; char** s = &str; if( !strhash ) strhash = hashinit( sizeof(char*), "strings" ); *s = (char*)string; if( hashenter( strhash, (HASHDATA **)&s ) ) { int l = strlen( string ); char *m = (char *)malloc( l + 1 ); strtotal += l + 1; memcpy( m, string, l + 1 ); *s = m; } return *s; } /* * copystr() - return a copy of a string previously returned by newstr() */ const char * String::copystr( const char *s ) { return s; } /* * freestr() - free a string returned by newstr() or copystr() */ void String::freestr( const char *s ) { } /* * donestr() - free string tables */ void String::donestr() { hashdone( strhash ); if( DEBUG_MEM ) printf( "%dK in strings\n", strtotal / 1024 ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 1153 | bob_summerwill | NewStr has been renamed as String. | ||
//guest/bob_summerwill/jam/src/NewStr.cpp | |||||
#3 | 1146 | bob_summerwill | Moved the NewStr global functions into a static class Jam::String. | ||
#2 | 1138 | bob_summerwill | Removed all extern "C" wrappers, so the program now has C++ linkage throughout, ready for refactoring. | ||
#1 | 1130 | bob_summerwill | More .C to .CPP conversions. | ||
//guest/bob_summerwill/jam/src/newstr.c | |||||
#5 | 1127 | bob_summerwill | More file renaming. | ||
#4 | 1126 | bob_summerwill | #include dependencies between headers are now modelled explicitly, with #includes as required in header files, rather than it being a client-code responsibility. | ||
#3 | 1120 | bob_summerwill | A fair-size chunk of char* const-correctness modifications. | ||
#2 | 1117 | bob_summerwill |
Converted Compile and Expand files to C++. Some minor function prototype tweaks. |
||
#1 | 1106 | bob_summerwill | Integrated Jam from "public" to "guest/bob_summerwill". | ||
//guest/perforce_software/jam/src/newstr.c | |||||
#2 | 486 | Perforce staff |
Jam 2.3. See RELNOTES for a list of changes from 2.2.x. Just about every source file was touched when jam got ANSI-fied. |
||
#1 | 2 | laura | Add Jam/MR 2.2 source |