Skip to content

Commit be446f2

Browse files
committed
try const string for delimit retval
1 parent c346de4 commit be446f2

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

src/cllazyfile/lazyInstMgr.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ fileID lazyInstMgr::registerLazyFile( lazyFileReader * freader ) {
2121

2222
void lazyInstMgr::addLazyInstance( namedLazyInstance inst ) {
2323
_lazyInstanceCount++;
24-
if( inst.name->length() > _longestTypeNameLen ) {
25-
_longestTypeNameLen = inst.name->length();
24+
int len = inst.name->length();
25+
if( len > _longestTypeNameLen ) {
26+
_longestTypeNameLen = len;
2627
_longestTypeName = *inst.name;
2728
}
2829
_instanceStreamPosMMap.insert( instanceStreamPosMMap_pair( inst.loc.instance, inst.loc ) );
2930
_instanceTypeMMap.insert( instanceTypeMMap_pair( *inst.name, inst.loc.instance ) );
30-
delete inst.name;
31+
// delete inst.name;
3132
}
3233

3334
unsigned long lazyInstMgr::getNumTypes() /*const*/ {

src/cllazyfile/lazyP21DataSectionReader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const namedLazyInstance lazyP21DataSectionReader::nextInstance() {
5656
if( ( !_file.good() ) || ( end == -1 ) ) {
5757
//invalid instance, so clear everything
5858
i.loc.begin = -1;
59-
delete i.name;
59+
// delete i.name;
6060
i.name = 0;
6161
}
6262
return i;

src/cllazyfile/lazyTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef struct {
3434
/// used when populating the instance type map \sa lazyInstMgr::_instanceTypeMMap
3535
typedef struct {
3636
lazyInstanceLoc loc;
37-
std::string * name;
37+
const std::string * name;
3838
} namedLazyInstance;
3939

4040
// instanceRefMMap - multimap between an instanceID and instances that refer to it

src/cllazyfile/p21HeaderSectionReader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const namedLazyInstance p21HeaderSectionReader::nextInstance() {
5050
if( (end == -1 ) || ( end >= _sectionEnd ) ) {
5151
//invalid instance, so clear everything
5252
i.loc.begin = -1;
53-
delete i.name;
53+
// delete i.name;
5454
i.name = 0;
5555
}
5656
}

src/cllazyfile/sectionReader.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ std::streampos sectionReader::findNormalString( const std::string& str, bool sem
7373
}
7474

7575
//NOTE different behavior than const char * GetKeyword( istream & in, const char * delims, ErrorDescriptor & err ) in read_func.cc
76-
std::string * sectionReader::getDelimitedKeyword( const char * delimiters ) {
77-
std::string * str = new std::string;
76+
const std::string * sectionReader::getDelimitedKeyword( const char * delimiters ) {
77+
static std::string str;
7878
char c;
79-
str->reserve(10); //seems to be faster and require less memory than no reserve or 20.
79+
// str->reserve(10); //seems to be faster and require less memory than no reserve or 20.
80+
str.clear();
8081
skipWS();
8182
while( c = _file.get(), _file.good() ) {
8283
if( c == '-' || c == '_' || isupper( c ) || isdigit( c ) ||
83-
( c == '!' && str->length() == 0 ) ) {
84-
str->append( 1, c );
85-
} else if( ( c == '/' ) && ( _file.peek() == '*' ) && ( str->length() == 0 ) ) {
84+
( c == '!' && str.length() == 0 ) ) {
85+
str.append( 1, c );
86+
} else if( ( c == '/' ) && ( _file.peek() == '*' ) && ( str.length() == 0 ) ) {
8687
//push past comment
8788
findNormalString( "*/" );
8889
skipWS();
@@ -94,10 +95,10 @@ std::string * sectionReader::getDelimitedKeyword( const char * delimiters ) {
9495
}
9596
c = _file.peek();
9697
if( !strchr( delimiters, c ) ) {
97-
std::cerr << __PRETTY_FUNCTION__ << ": missing delimiter. Found " << c << ", expected one of " << delimiters << " at end of keyword " << *str << ". File offset: " << _file.tellg() << std::endl;
98+
std::cerr << __PRETTY_FUNCTION__ << ": missing delimiter. Found " << c << ", expected one of " << delimiters << " at end of keyword " << str << ". File offset: " << _file.tellg() << std::endl;
9899
abort();
99100
}
100-
return str;
101+
return &str;
101102
}
102103

103104
std::streampos sectionReader::seekInstanceEnd() {

src/cllazyfile/sectionReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class sectionReader {
3939

4040
/** Get a keyword ending with one of delimiters.
4141
*/
42-
std::string * getDelimitedKeyword( const char * delimiters );
42+
const std::string * getDelimitedKeyword( const char * delimiters );
4343

4444
/** Seek to the end of the current instance */
4545
std::streampos seekInstanceEnd();

0 commit comments

Comments
 (0)