File tree Expand file tree Collapse file tree 1 file changed +11
-13
lines changed
src/actions/transformations Expand file tree Collapse file tree 1 file changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -25,29 +25,27 @@ CompressWhitespace::CompressWhitespace(const std::string &action)
2525}
2626
2727bool CompressWhitespace::transform (std::string &value, const Transaction *trans) const {
28+ bool inWhiteSpace = false ;
2829
29- std::string a;
30- int inWhiteSpace = 0 ;
31- int i = 0 ;
30+ auto d = value.data ();
3231
33- while (i < value. size () ) {
34- if (isspace (value[i] )) {
32+ for ( const auto c : value) {
33+ if (isspace (c )) {
3534 if (inWhiteSpace) {
36- i++;
3735 continue ;
3836 } else {
39- inWhiteSpace = 1 ;
40- a. append ( " " , 1 ) ;
37+ inWhiteSpace = true ;
38+ *d++ = ' ' ;
4139 }
4240 } else {
43- inWhiteSpace = 0 ;
44- a. append (&value. at (i), 1 ) ;
41+ inWhiteSpace = false ;
42+ *d++ = c ;
4543 }
46- i++;
4744 }
4845
49- const auto changed = a != value;
50- value = a;
46+ const auto new_len = d - value.c_str ();
47+ const auto changed = new_len != value.length ();
48+ value.resize (new_len);
5149 return changed;
5250}
5351
You can’t perform that action at this time.
0 commit comments