forked from TravelMapping/DataProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
macros
Every macro you write makes you less 1337.
-Some random person on the internet.
While not 100% the case across the board, there's some truthiness to it.
Lambdas will work in many cases. Advantages include:
- Safer
- Smaller program size
- Speed? Instruction cache?
Can't get rid of all of them, but here are some candidates:
- Just use a reference for this one, not a lambda, but including it anyway.
#define G GraphListEntry::entries[g] -
#define CSV_LINE r.system->systemname + ".csv#L" + std::to_string(r.index()+2) -
#define PYTHON_STYLE_FLOAT(F) e=sprintf(s," %.15g",F); if (F==int(F)) strcpy(s+e,".0"); nmpnmp<<s; - Binary size down 4000 B. Gets used 8 times.
#define FLAG(SUBTYPE) Datacheck::add(route, label, "", "", "LABEL_SELFREF", SUBTYPE) - This may not work, with the continue in the lambda and not the body of the loop itself? Try it & see what happens.
#define SKIP {--points.size; if (segments.size) /*cope with all-whitespace files*/ --segments.size; continue;} -
#define ARG(N,S,L) ( n+N < argc && (!strcmp(argv[n],S) || !strcmp(argv[n],L)) ) - Eventually, the need for these macros will go away entirely. But that's a heavyweight operation that'll take some time to get around to. In the interim, could this maybe have an effect if it's easier on instruction cache?
Edit: Deleted in 897c231. No need for a lambda.
DataProcessing/siteupdate/cplusplus/classes/GraphGeneration/get_subgraph_data.cpp
Lines 38 to 39 in 387c99b
#define AREA (!g->placeradius || subgraph_contains(e->vertex1, threadnum) && subgraph_contains(e->vertex2, threadnum)) #define REGION (!g->regions || contains(*g->regions, e->segment->route->region)) - Eventually, HGEdge::detach may go away entirely (another heavyweight opeation). If this does help in the interim; it'll be low-impact; edge compression is already pretty fast and may get faster.
Edit: It's still here, just smaller & called less often. The lambda is invoked twice, as opposed to the macro being invoked 6 times.
DataProcessing/siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp
Lines 122 to 127 in 387c99b
#define DETACH(v) \ for (std::list<HGEdge*>::iterator e = v.begin(); e != v.end(); e++) \ if (*e == this) \ { v.erase(e); \ break; \ } -
DataProcessing/siteupdate/cplusplus/classes/TravelerList/TravelerList.cpp
Lines 126 to 129 in 387c99b
#define UPDATE_NOTE(R) if (R->last_update) \ { updated_routes.insert(R); \ log << " Route updated " << R->last_update[0] << ": " << R->readable_name() << '\n'; \ }
other stuff
- datacheck boilerplate
A couple examples are above already, but in general, look forDatacheck::add. - sorting
grep -n 'sort([^)]' \`find . -name \*.cpp`- Sorting regions.csv lines & eliminating the 1 use of
sort_1st_csv_fieldreduces binary size 144 B. -
sort_route_updates_oldest - What if a function is used multiple times, i.e.
sort_root_at_label(5x)?
- Sorting regions.csv lines & eliminating the 1 use of
- splitregion.cpp