mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-02-02 12:19:18 +00:00
Refactor to improve the compile time of "langen.cpp".
$ time c++ -std=c++11 -march=native -DMAC -I/usr/local/include -DCAP_PNG=0 -O0 -w langen.cpp -o langen real 0m3.174s user 0m2.985s sys 0m0.179s
This commit is contained in:
parent
172d2c2d1b
commit
dd1a842285
115
langen.cpp
115
langen.cpp
@ -24,20 +24,29 @@ const char *escape(std::string s, const std::string& dft);
|
|||||||
|
|
||||||
template<class T> struct dictionary {
|
template<class T> struct dictionary {
|
||||||
std::map<std::string, T> m;
|
std::map<std::string, T> m;
|
||||||
void add(const std::string& s, const T& val) {
|
void add(const std::string& s, T val) {
|
||||||
if(m.count(s)) add(s + " [repeat]", val);
|
if(m.count(s)) add(s + " [repeat]", std::move(val));
|
||||||
else m[s] = val;
|
else m[s] = std::move(val);
|
||||||
}
|
}
|
||||||
T& operator [] (const std::string& s) { return m[s]; }
|
T& operator [] (const std::string& s) { return m[s]; }
|
||||||
int count(const std::string& s) { return m.count(s); }
|
int count(const std::string& s) { return m.count(s); }
|
||||||
void clear() { m.clear(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary<std::string> d[NUMLAN];
|
dictionary<std::string> d[NUMLAN];
|
||||||
|
|
||||||
|
struct noun2 {
|
||||||
|
int genus;
|
||||||
|
const char *nom;
|
||||||
|
const char *nomp;
|
||||||
|
const char *acc;
|
||||||
|
const char *abl;
|
||||||
|
};
|
||||||
|
|
||||||
struct noun {
|
struct noun {
|
||||||
int genus;
|
int genus;
|
||||||
std::string nom, nomp, acc, abl;
|
std::string nom, nomp, acc, abl;
|
||||||
|
noun() = default;
|
||||||
|
noun(const noun2& n) : genus(n.genus), nom(n.nom), nomp(n.nomp), acc(n.acc), abl(n.abl) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary<noun> nouns[NUMLAN];
|
dictionary<noun> nouns[NUMLAN];
|
||||||
@ -118,59 +127,117 @@ std::set<std::string> nothe;
|
|||||||
std::set<std::string> plural;
|
std::set<std::string> plural;
|
||||||
|
|
||||||
void langPL() {
|
void langPL() {
|
||||||
#define S(a,b) d[1].add(a,b);
|
static std::pair<const char *, const char *> ds[] = {
|
||||||
#define N(a,b,c,d,e,f) \
|
#define S(a,b) { a, b },
|
||||||
{noun n; n.genus = b; n.nom = c; n.nomp = d; n.acc = e; n.abl = f; nouns[1].add(a,n);}
|
#define N(a,b,c,d,e,f)
|
||||||
#include "language-pl.cpp"
|
#include "language-pl.cpp"
|
||||||
#undef N
|
#undef N
|
||||||
#undef S
|
#undef S
|
||||||
|
};
|
||||||
|
static std::pair<const char *, noun2> ns[] = {
|
||||||
|
#define S(a,b)
|
||||||
|
#define N(a,b,c,d,e,f) { a, noun2{ b, c, d, e, f } },
|
||||||
|
#include "language-pl.cpp"
|
||||||
|
#undef N
|
||||||
|
#undef S
|
||||||
|
};
|
||||||
|
for(auto&& elt : ds) d[1].add(elt.first, elt.second);
|
||||||
|
for(auto&& elt : ns) nouns[1].add(elt.first, elt.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void langTR() {
|
void langTR() {
|
||||||
#define S(a,b) d[2].add(a,b);
|
static std::pair<const char *, const char *> ds[] = {
|
||||||
#define N5(a,b,c,d,e) \
|
#define S(a,b) { a, b },
|
||||||
{noun n; n.genus = b; n.nom = c; n.nomp = d; n.acc = e; n.abl = e; nouns[2].add(a,n);}
|
#define N(a,b,c,d,e,f)
|
||||||
#define N(a,b,c,d,e,f) \
|
|
||||||
{noun n; n.genus = b; n.nom = c; n.nomp = d; n.acc = e; n.abl = f; nouns[2].add(a,n);}
|
|
||||||
#include "language-tr.cpp"
|
#include "language-tr.cpp"
|
||||||
#undef N
|
#undef N
|
||||||
#undef S
|
#undef S
|
||||||
|
};
|
||||||
|
static std::pair<const char *, noun2> ns[] = {
|
||||||
|
#define S(a,b)
|
||||||
|
#define N(a,b,c,d,e,f) { a, noun2{ b, c, d, e, f } },
|
||||||
|
#include "language-tr.cpp"
|
||||||
|
#undef N
|
||||||
|
#undef S
|
||||||
|
};
|
||||||
|
for(auto&& elt : ds) d[2].add(elt.first, elt.second);
|
||||||
|
for(auto&& elt : ns) nouns[2].add(elt.first, elt.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void langCZ() {
|
void langCZ() {
|
||||||
#define S(a,b) d[3].add(a,b);
|
static std::pair<const char *, const char *> ds[] = {
|
||||||
#define N(a,b,c,d,e,f) \
|
#define S(a,b) { a, b },
|
||||||
{noun n; n.genus = b; n.nom = c; n.nomp = d; n.acc = e; n.abl = f; nouns[3].add(a,n);}
|
#define N(a,b,c,d,e,f)
|
||||||
#include "language-cz.cpp"
|
#include "language-cz.cpp"
|
||||||
#undef N
|
#undef N
|
||||||
#undef S
|
#undef S
|
||||||
|
};
|
||||||
|
static std::pair<const char *, noun2> ns[] = {
|
||||||
|
#define S(a,b)
|
||||||
|
#define N(a,b,c,d,e,f) { a, noun2{ b, c, d, e, f } },
|
||||||
|
#include "language-cz.cpp"
|
||||||
|
#undef N
|
||||||
|
#undef S
|
||||||
|
};
|
||||||
|
for(auto&& elt : ds) d[3].add(elt.first, elt.second);
|
||||||
|
for(auto&& elt : ns) nouns[3].add(elt.first, elt.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void langRU() {
|
void langRU() {
|
||||||
#define S(a,b) d[4].add(a,b);
|
static std::pair<const char *, const char *> ds[] = {
|
||||||
#define N(a,b,c,d,e,f) \
|
#define S(a,b) { a, b },
|
||||||
{noun n; n.genus = b; n.nom = c; n.nomp = d; n.acc = e; n.abl = f; nouns[4].add(a,n);}
|
#define N(a,b,c,d,e,f)
|
||||||
#include "language-ru.cpp"
|
#include "language-ru.cpp"
|
||||||
#undef N
|
#undef N
|
||||||
#undef S
|
#undef S
|
||||||
|
};
|
||||||
|
static std::pair<const char *, noun2> ns[] = {
|
||||||
|
#define S(a,b)
|
||||||
|
#define N(a,b,c,d,e,f) { a, noun2{ b, c, d, e, f } },
|
||||||
|
#include "language-ru.cpp"
|
||||||
|
#undef N
|
||||||
|
#undef S
|
||||||
|
};
|
||||||
|
for(auto&& elt : ds) d[4].add(elt.first, elt.second);
|
||||||
|
for(auto&& elt : ns) nouns[4].add(elt.first, elt.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void langDE() {
|
void langDE() {
|
||||||
#define S(a,b) d[5].add(a,b);
|
static std::pair<const char *, const char *> ds[] = {
|
||||||
#define N(a,b,c,d,e) \
|
#define S(a,b) { a, b },
|
||||||
{noun n; n.genus = b; n.nom = c; n.nomp = d; n.acc = e; n.abl = e; nouns[5].add(a,n);}
|
#define N(a,b,c,d,e)
|
||||||
#include "language-de.cpp"
|
#include "language-de.cpp"
|
||||||
#undef N
|
#undef N
|
||||||
#undef S
|
#undef S
|
||||||
|
};
|
||||||
|
static std::pair<const char *, noun2> ns[] = {
|
||||||
|
#define S(a,b)
|
||||||
|
#define N(a,b,c,d,e) { a, noun2{ b, c, d, e, e } },
|
||||||
|
#include "language-de.cpp"
|
||||||
|
#undef N
|
||||||
|
#undef S
|
||||||
|
};
|
||||||
|
for(auto&& elt : ds) d[5].add(elt.first, elt.second);
|
||||||
|
for(auto&& elt : ns) nouns[5].add(elt.first, elt.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void langPT() {
|
void langPT() {
|
||||||
#define S(a,b) d[6].add(a,b);
|
static std::pair<const char *, const char *> ds[] = {
|
||||||
#define N(a,b,c,d,e) \
|
#define S(a,b) { a, b },
|
||||||
{noun n; n.genus = b; n.nom = c; n.nomp = d; n.abl = e; nouns[6].add(a,n);}
|
#define N(a,b,c,d,e)
|
||||||
#include "language-ptbr.cpp"
|
#include "language-ptbr.cpp"
|
||||||
#undef N
|
#undef N
|
||||||
#undef S
|
#undef S
|
||||||
|
};
|
||||||
|
static std::pair<const char *, noun2> ns[] = {
|
||||||
|
#define S(a,b)
|
||||||
|
#define N(a,b,c,d,e) { a, noun2{ b, c, d, "", e } },
|
||||||
|
#include "language-ptbr.cpp"
|
||||||
|
#undef N
|
||||||
|
#undef S
|
||||||
|
};
|
||||||
|
for(auto&& elt : ds) d[6].add(elt.first, elt.second);
|
||||||
|
for(auto&& elt : ns) nouns[6].add(elt.first, elt.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
int completeness[NUMLAN];
|
int completeness[NUMLAN];
|
||||||
|
Loading…
Reference in New Issue
Block a user