Skip to content

Commit e37b471

Browse files
committed
Apparently for loops are faster than foreach: ~13s
1 parent 39dde84 commit e37b471

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

stencil.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ void parse_and_compile() {
9797
CODE[code_counter] = STENCIL_INSTRUCTION;
9898
STENCILS[code_counter] = build_stencil();
9999
++code_counter;
100-
/*
101-
CODE[code_counter] = input;
102-
++code_counter;
103-
CODE[code_counter] = parse_run(input);
104-
++code_counter;
105-
*/
106100
break;
107101
case '.':
108102
case ',':
@@ -133,25 +127,17 @@ void run() {
133127
for (unsigned char *code_ptr = CODE;
134128
code_ptr < &CODE[CODESIZE];
135129
code_ptr++) {
136-
/*
137-
if (*code_ptr > 0) {
138-
cout << "I: " << *code_ptr << "\n";
139-
}
140-
*/
141130
switch(*code_ptr) {
142131
case STENCIL_INSTRUCTION:
143132
stencil = &STENCILS[code_ptr-CODE];
144-
/*
145-
cout << "C" << data_ptr-DATA << " O" << stencil.offset
146-
<< " M" << stencil.move << " V";
147-
print_vec(stencil.cells);
148-
*/
149133
tmp_data_ptr = data_ptr - stencil->offset;
150-
for (auto& cell : stencil->cells) {
151-
*tmp_data_ptr = (unsigned char) *tmp_data_ptr + cell;
134+
data_ptr += stencil->move;
135+
136+
for (unsigned int i= 0; i < stencil->cells.size(); ++i) {
137+
*tmp_data_ptr = (unsigned char) *tmp_data_ptr +
138+
stencil->cells[i];
152139
++tmp_data_ptr;
153140
}
154-
data_ptr += stencil->move;
155141
break;
156142
case '<':
157143
++code_ptr;

0 commit comments

Comments
 (0)