File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -37,16 +37,15 @@ class MTF {
37
37
38
38
generateSymbols ();
39
39
40
- std::string encoded;
41
- for (uint8_t symbol : toBeEncoded) {
40
+ for (auto & symbol : toBeEncoded) {
42
41
auto ptr = getIndexOfValue (symbol);
43
- encoded + = ptr.index ;
42
+ symbol = ptr.index ; // Encode in-place
44
43
symbolsList.erase (ptr.iterator );
45
- symbolsList.push_front (symbol );
44
+ symbolsList.push_front (ptr. value );
46
45
}
47
46
48
47
remove (outputFileName.c_str ()); // Remove Output File If Exists
49
- BinaryIO::write (outputFileName, encoded );
48
+ BinaryIO::write (outputFileName, toBeEncoded );
50
49
51
50
}
52
51
@@ -56,16 +55,16 @@ class MTF {
56
55
57
56
generateSymbols ();
58
57
59
- std::string decoded;
60
- for ( uint8_t index : toBeDecoded) {
58
+ for ( auto & byte : toBeDecoded) {
59
+ uint8_t index = byte;
61
60
auto ptr = getValueOfIndex (index);
62
- decoded + = ptr.value ;
61
+ byte = ptr.value ; // Decode in-place
63
62
symbolsList.erase (ptr.iterator );
64
63
symbolsList.push_front (ptr.value );
65
64
}
66
65
67
66
remove (outputFileName.c_str ()); // Remove Output File If Exists
68
- BinaryIO::write (outputFileName, decoded );
67
+ BinaryIO::write (outputFileName, toBeDecoded );
69
68
70
69
}
71
70
You can’t perform that action at this time.
0 commit comments