GcodeDisplay: Use iterator instead of indexing
authorBen Gamari <bgamari.foss@gmail.com>
Sun, 10 Feb 2013 21:53:38 +0000 (16:53 -0500)
committerBen Gamari <bgamari.foss@gmail.com>
Mon, 11 Feb 2013 00:02:21 +0000 (19:02 -0500)
This avoids allocations due to _M_leak since possible_command is
mutable.

src/modules/communication/GcodeDispatch.cpp

index a174994..1047651 100644 (file)
@@ -54,8 +54,8 @@ void GcodeDispatch::on_console_line_received(void * line){
             possible_command = possible_command.substr(0, chkpos);
             //Calculate checksum
             if( chkpos != string::npos ){
-                for(int i = 0; possible_command[i] != '*' && possible_command[i] != 0; i++)
-                    cs = cs ^ possible_command[i];
+                for(auto c = possible_command.cbegin(); *c != '*' && c != possible_command.cend(); c++)
+                    cs = cs ^ *c;
                 cs &= 0xff;  // Defensive programming...
                 cs -= chksum;
             }