From f36ddd7d82fe3d7ade0f8a2eaf9b9371ca9da513 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Wed, 6 Feb 2013 22:59:05 -0500 Subject: [PATCH] Gcode: Ensure std::string operations don't incur allocations --- src/modules/communication/utils/Gcode.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/communication/utils/Gcode.cpp b/src/modules/communication/utils/Gcode.cpp index c76c4cd6..ca75b196 100644 --- a/src/modules/communication/utils/Gcode.cpp +++ b/src/modules/communication/utils/Gcode.cpp @@ -35,8 +35,8 @@ Gcode::Gcode(string& command, StreamOutput* stream) // Whether or not a Gcode has a letter bool Gcode::has_letter( char letter ){ //return ( this->command->find( letter ) != string::npos ); - for (size_t i=0; i < this->command.length(); i++){ - if( this->command[i] == letter ){ + for (std::string::const_iterator c = this->command.cbegin(); c != this->command.cend(); c++) { + if( *c == letter ){ return true; } } @@ -48,7 +48,8 @@ bool Gcode::has_letter( char letter ){ double Gcode::get_value( char letter ){ //__disable_irq(); for (size_t i=0; i <= this->command.length()-1; i++){ - if( letter == this->command.at(i) ){ + const char c = this->command[i]; + if( letter == c ){ size_t beginning = i+1; char buffer[20]; for(size_t j=beginning; j <= this->command.length(); j++){ -- 2.20.1