From 3a39d18d199bd78eb27d4a77c722d2163e61bff0 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sat, 27 Dec 2008 00:03:20 +0000 Subject: [PATCH] Change one while loop to use stl algorithms and added TODO about slow part of code --- preprocessor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/preprocessor.cpp b/preprocessor.cpp index 4ac81f582..66a94ba90 100644 --- a/preprocessor.cpp +++ b/preprocessor.cpp @@ -154,14 +154,14 @@ void Preprocessor::preprocess(std::istream &istr, const std::string &filename, s processedFile = read(istr, filename); // Replace all tabs with spaces.. - std::string::size_type loc = 0; - while ( (loc = processedFile.find("\t", loc)) != std::string::npos ) - processedFile[loc] = ' '; + std::replace( processedFile.begin(), processedFile.end(), '\t', ' ' ); // Remove all indentation.. if ( !processedFile.empty() && processedFile[0] == ' ' ) processedFile.erase( 0, processedFile.find_first_not_of(" ") ); - loc = 0; + + // TODO, this is very slow with very big files, make it faster + std::string::size_type loc = 0; while ( (loc = processedFile.find("\n ", loc)) != std::string::npos ) processedFile.erase( 1 + loc, 1 );