Minor performance tweaks

This commit is contained in:
Brad Anderson 2017-10-24 21:48:28 -06:00
parent b2e08e4bc0
commit 85aac02172
1 changed files with 7 additions and 5 deletions

View File

@ -2489,7 +2489,7 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
for( int i=0; i<NUM_ENTITIES; ++i ) { for( int i=0; i<NUM_ENTITIES; ++i ) {
if ( entities[i].value == *q ) { if ( entities[i].value == *q ) {
Putc( '&' ); Putc( '&' );
Write( entities[i].pattern ); Write( entities[i].pattern, entities[i].length );
Putc( ';' ); Putc( ';' );
entityPatternPrinted = true; entityPatternPrinted = true;
break; break;
@ -2510,7 +2510,9 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
// string if an entity wasn't found. // string if an entity wasn't found.
TIXMLASSERT( p <= q ); TIXMLASSERT( p <= q );
if ( !_processEntities || ( p < q ) ) { if ( !_processEntities || ( p < q ) ) {
Write( p ); const size_t delta = q - p;
const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;
Write( p, toPrint );
} }
} }
@ -2551,11 +2553,11 @@ void XMLPrinter::OpenElement( const char* name, bool compactMode )
void XMLPrinter::PushAttribute( const char* name, const char* value ) void XMLPrinter::PushAttribute( const char* name, const char* value )
{ {
TIXMLASSERT( _elementJustOpened ); TIXMLASSERT( _elementJustOpened );
Write( " " ); Putc ( ' ' );
Write( name ); Write( name );
Write( "=\"" ); Write( "=\"" );
PrintString( value, false ); PrintString( value, false );
Write( "\"" ); Putc ( '\"' );
} }
@ -2740,7 +2742,7 @@ void XMLPrinter::PushUnknown( const char* value )
Write( "<!" ); Write( "<!" );
Write( value ); Write( value );
Write( ">" ); Putc( '>' );
} }