3259
Prefer preincrement operators wherever possible. Old versions of compilers used to be better at optimizing them. Even if we don't care about performance it's useful to make unary operators look like unary operators wherever possible, and to distinguish the 'statement form' which doesn't care about the value of the expression from the postincrement which usually increments as a side-effect in some larger computation (and so is worth avoiding except for some common idioms, or perhaps even there).
This commit is contained in:
parent
029a3bdf53
commit
7fd010710c
|
@ -127,7 +127,7 @@ bool next_instruction(istream& in, instruction* curr) {
|
|||
raise << "instruction prematurely ended with '<-'\n" << end();
|
||||
return false;
|
||||
}
|
||||
curr->old_name = curr->name = *p; p++;
|
||||
curr->old_name = curr->name = *p; ++p;
|
||||
// curr->operation will be set in a later layer
|
||||
|
||||
for (; p != words.end(); ++p)
|
||||
|
|
|
@ -148,8 +148,8 @@ load_file_or_directory("core.mu");
|
|||
//? START_TRACING_UNTIL_END_OF_SCOPE
|
||||
if (argc > 1) {
|
||||
// skip argv[0]
|
||||
argv++;
|
||||
argc--;
|
||||
++argv;
|
||||
--argc;
|
||||
// ignore argv past '--'; that's commandline args for 'main'
|
||||
while (argc > 0) {
|
||||
if (string(*argv) == "--") break;
|
||||
|
|
|
@ -285,10 +285,10 @@ case ALLOCATE: {
|
|||
:(code)
|
||||
int allocate(int size) {
|
||||
// include space for refcount
|
||||
size++;
|
||||
++size;
|
||||
trace(9999, "mem") << "allocating size " << size << end();
|
||||
//? Total_alloc += size;
|
||||
//? Num_alloc++;
|
||||
//? ++Num_alloc;
|
||||
// Allocate Special-cases
|
||||
// compute the region of memory to return
|
||||
// really crappy at the moment
|
||||
|
|
|
@ -28,7 +28,7 @@ map<int, int> free_list;
|
|||
void abandon(int address, const type_tree* payload_type, int payload_size) {
|
||||
trace(9999, "abandon") << "updating refcounts inside " << address << ": " << to_string(payload_type) << end();
|
||||
//? Total_free += size;
|
||||
//? Num_free++;
|
||||
//? ++Num_free;
|
||||
//? cerr << "abandon: " << size << '\n';
|
||||
// decrement any contained refcounts
|
||||
if (payload_type->name == "array") {
|
||||
|
|
|
@ -35,7 +35,7 @@ int new_mu_string(const string& contents) {
|
|||
// allocate an array just large enough for it
|
||||
int string_length = unicode_length(contents);
|
||||
//? Total_alloc += string_length+1;
|
||||
//? Num_alloc++;
|
||||
//? ++Num_alloc;
|
||||
int result = allocate(string_length+/*array size*/1);
|
||||
trace(9999, "mem") << "storing string refcount 0 in location " << result << end();
|
||||
put(Memory, result, 0);
|
||||
|
@ -124,7 +124,7 @@ int unicode_length(const string& s) {
|
|||
|
||||
string read_mu_string(int address) {
|
||||
if (address == 0) return "";
|
||||
address++; // skip refcount
|
||||
++address; // skip refcount
|
||||
int size = get_or_insert(Memory, address);
|
||||
if (size == 0) return "";
|
||||
ostringstream tmp;
|
||||
|
|
|
@ -194,7 +194,7 @@ int number_of_concrete_type_names(const type_tree* type) {
|
|||
if (!type) return 0;
|
||||
int result = 0;
|
||||
if (!type->name.empty() && !is_type_ingredient_name(type->name))
|
||||
result++;
|
||||
++result;
|
||||
result += number_of_concrete_type_names(type->left);
|
||||
result += number_of_concrete_type_names(type->right);
|
||||
return result;
|
||||
|
|
|
@ -137,7 +137,7 @@ int Next_routine_id = 1;
|
|||
Next_routine_id = 1;
|
||||
:(before "End routine Constructor")
|
||||
id = Next_routine_id;
|
||||
Next_routine_id++;
|
||||
++Next_routine_id;
|
||||
|
||||
//: routines save the routine that spawned them
|
||||
:(before "End routine Fields")
|
||||
|
|
|
@ -223,7 +223,7 @@ case MOVE_CURSOR_DOWN_ON_DISPLAY: {
|
|||
int h=tb_height();
|
||||
int height = (h >= 0) ? h : 0;
|
||||
if (Display_row < height-1) {
|
||||
Display_row++;
|
||||
++Display_row;
|
||||
tb_set_cursor(Display_column, Display_row);
|
||||
if (Autodisplay) tb_present();
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ case MOVE_CURSOR_UP_ON_DISPLAY: {
|
|||
:(before "End Primitive Recipe Implementations")
|
||||
case MOVE_CURSOR_UP_ON_DISPLAY: {
|
||||
if (Display_row > 0) {
|
||||
Display_row--;
|
||||
--Display_row;
|
||||
tb_set_cursor(Display_column, Display_row);
|
||||
if (Autodisplay) tb_present();
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ case MOVE_CURSOR_RIGHT_ON_DISPLAY: {
|
|||
int w=tb_width();
|
||||
int width = (w >= 0) ? w : 0;
|
||||
if (Display_column < width-1) {
|
||||
Display_column++;
|
||||
++Display_column;
|
||||
tb_set_cursor(Display_column, Display_row);
|
||||
if (Autodisplay) tb_present();
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ case MOVE_CURSOR_LEFT_ON_DISPLAY: {
|
|||
:(before "End Primitive Recipe Implementations")
|
||||
case MOVE_CURSOR_LEFT_ON_DISPLAY: {
|
||||
if (Display_column > 0) {
|
||||
Display_column--;
|
||||
--Display_column;
|
||||
tb_set_cursor(Display_column, Display_row);
|
||||
if (Autodisplay) tb_present();
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ else if (tb_is_active()) {
|
|||
}
|
||||
:(code)
|
||||
void move_cursor_to_start_of_next_line_on_display() {
|
||||
if (Display_row < tb_height()-1) Display_row++;
|
||||
if (Display_row < tb_height()-1) ++Display_row;
|
||||
else Display_row = 0;
|
||||
Display_column = 0;
|
||||
tb_set_cursor(Display_column, Display_row);
|
||||
|
|
|
@ -273,7 +273,7 @@ int count_events(const recipe& r) {
|
|||
if (curr.name == "type")
|
||||
result += unicode_length(curr.ingredients.at(0).name);
|
||||
else
|
||||
result++;
|
||||
++result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -195,12 +195,12 @@ void construct_filesystem_object(const map<string, string>& contents) {
|
|||
trace(9999, "mem") << "storing file name " << get(Memory, curr) << " in location " << curr << end();
|
||||
put(Memory, get(Memory, curr), 1);
|
||||
trace(9999, "mem") << "storing refcount 1 in location " << get(Memory, curr) << end();
|
||||
curr++;
|
||||
++curr;
|
||||
put(Memory, curr, new_mu_string(p->second));
|
||||
trace(9999, "mem") << "storing file contents " << get(Memory, curr) << " in location " << curr << end();
|
||||
put(Memory, get(Memory, curr), 1);
|
||||
trace(9999, "mem") << "storing refcount 1 in location " << get(Memory, curr) << end();
|
||||
curr++;
|
||||
++curr;
|
||||
}
|
||||
curr = filesystem_data_address+/*skip refcount*/1;
|
||||
put(Memory, curr, SIZE(contents)); // size of array
|
||||
|
|
Loading…
Reference in New Issue