diff --git a/include/kicad_exceptions.h b/include/kicad_exceptions.h index 5fac9a6626..e220e87835 100644 --- a/include/kicad_exceptions.h +++ b/include/kicad_exceptions.h @@ -42,6 +42,11 @@ struct IO_ERROR { wxString errorText; + IO_ERROR( const wxChar* aMsg ) : + errorText( aMsg ) + { + } + IO_ERROR( const wxString& aMsg ) : errorText( aMsg ) { diff --git a/new/sch_dir_lib_source.cpp b/new/sch_dir_lib_source.cpp index b8a43bf807..4809c2bc77 100644 --- a/new/sch_dir_lib_source.cpp +++ b/new/sch_dir_lib_source.cpp @@ -50,7 +50,6 @@ using namespace SCH; #include #include #include -#include #include #include @@ -66,6 +65,7 @@ using namespace std; /// implementation, and to a corresponding LIB_SINK. /// Core EESCHEMA should never have to see this. #define SWEET_EXT ".part" +#define SWEET_EXTZ (sizeof(SWEET_EXT)-1) /* __func__ is C99 prescribed, but just in case: @@ -141,6 +141,12 @@ static const char* strrstr( const char* haystack, const char* needle ) } +static inline bool isDigit( char c ) +{ + return c >= '0' && c <= '9'; +} + + /** * Function endsWithRev * returns a pointer to the final string segment: "revN[N..]" or NULL if none. @@ -154,7 +160,7 @@ static const char* endsWithRev( const char* start, const char* tail, char separa { bool sawDigit = false; - while( tail > start && isdigit( *--tail ) ) + while( tail > start && isDigit( *--tail ) ) { sawDigit = true; } @@ -237,7 +243,7 @@ bool DIR_LIB_SOURCE::makePartName( STRING* aPartName, const char* aEntry, // If versioning, then must find a trailing "revN.." type of string. if( useVersioning ) { - const char* rev = endsWithRev( cp + sizeof(SWEET_EXT) - 1, limit, '.' ); + const char* rev = endsWithRev( cp + SWEET_EXTZ, limit, '.' ); if( rev ) { if( aCategory.size() ) @@ -397,7 +403,7 @@ void DIR_LIB_SOURCE::GetCategoricalPartNames( STRINGS* aResults, const STRING& a while( it != limit ) { - const char* rev = endsWithRev( *it, '/' ); + const char* rev = endsWithRev( *it, '/' ); // all cached partnames have a rev string in useVersioning mode assert( rev ); diff --git a/new/sch_lib_table.cpp b/new/sch_lib_table.cpp index ad2710faef..3c6f39005f 100644 --- a/new/sch_lib_table.cpp +++ b/new/sch_lib_table.cpp @@ -171,11 +171,10 @@ const LIB_TABLE::ROW* LIB_TABLE::FindRow( const STRING& aLogicalName ) // ptr_map<> was used instead of ptr_set<>, which would have required // instantiating a ROW just to find a ROW. LIB_TABLE* cur = this; - ROWS_CITER it; do { - it = cur->rows.find( aLogicalName ); + ROWS_CITER it = cur->rows.find( aLogicalName ); if( it != cur->rows.end() ) { @@ -192,9 +191,11 @@ const LIB_TABLE::ROW* LIB_TABLE::FindRow( const STRING& aLogicalName ) bool LIB_TABLE::InsertRow( auto_ptr& aRow, bool doReplace ) { - ROWS_ITER it = rows.find( aRow->logicalName ); + // this does not need to be super fast. - if( doReplace || it == rows.end() ) + ROWS_CITER it = rows.find( aRow->logicalName ); + + if( it == rows.end() ) { // be careful here, key is needed because aRow can be // release()ed before logicalName is captured. @@ -202,6 +203,16 @@ bool LIB_TABLE::InsertRow( auto_ptr& aRow, bool doReplace ) rows.insert( key, aRow ); return true; } + else if( doReplace ) + { + rows.erase( aRow->logicalName ); + + // be careful here, key is needed because aRow can be + // release()ed before logicalName is captured. + const STRING& key = aRow->logicalName; + rows.insert( key, aRow ); + return true; + } return false; }