Skip to content

Commit

Permalink
Remove compressed list and signed left shift template stuff. Improved…
Browse files Browse the repository at this point in the history
… performance of map/set/hash code.
  • Loading branch information
graphitemaster committed Aug 11, 2015
1 parent 2d8ecf3 commit 6994571
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 559 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -20,7 +20,7 @@ CXXFLAGS = \
ifneq (, $(findstring -g, $(CXXFLAGS)))
STRIP = true
else
STRIP = strip
STRIP = true #strip
endif

ENGINE_CXXFLAGS = \
Expand Down
6 changes: 3 additions & 3 deletions game/menu.cpp
Expand Up @@ -305,7 +305,7 @@ static void menuOptions() {
int findResolution = -1;
for (auto &it : kResolutionPairs) {
for (auto &jt : it) {
if (jt.first() == width.get() && jt.second() == height.get()) {
if (jt.first == width.get() && jt.second == height.get()) {
findRatio = &it - kResolutionPairs.begin();
findResolution = &jt - it.begin();
break;
Expand All @@ -322,8 +322,8 @@ static void menuOptions() {
D(resolution) = gui::selector(nullptr, D(resolution), kResolutionStrings[D(ratio)]);

auto resolution = kResolutionPairs[D(ratio)][D(resolution)];
width.set(resolution.first());
height.set(resolution.second());
width.set(resolution.first);
height.set(resolution.second);
gui::dedent();

}
Expand Down
4 changes: 2 additions & 2 deletions model.cpp
Expand Up @@ -356,8 +356,8 @@ struct inData {
}

void operator=(const u::pair<uint32_t, unsigned char *> &data) {
isHalf = data.first() == iqm::kHalf;
asOpaque = data.second();
isHalf = data.first == iqm::kHalf;
asOpaque = data.second;
}

void endianSwap(size_t count) {
Expand Down
20 changes: 11 additions & 9 deletions texture.cpp
Expand Up @@ -200,19 +200,21 @@ struct jpeg : decoder {
static constexpr int kW7 = 565;

// fast integer discrete cosine transform
#define sls(X, Y) (int)((unsigned int)(X) << (Y))

void rowIDCT(int* blk) {
int x0, x1, x2, x3, x4, x5, x6, x7, x8;
if (!((x1 = u::sls(blk[4], 11))
if (!((x1 = sls(blk[4], 11))
| (x2 = blk[6]) | (x3 = blk[2])
| (x4 = blk[1]) | (x5 = blk[7])
| (x6 = blk[5]) | (x7 = blk[3])))
{
int value = u::sls(blk[0], 3);
int value = sls(blk[0], 3);
for (size_t i = 0; i < 8; i++)
blk[i] = value;
return;
}
x0 = u::sls(blk[0], 11) + 128;
x0 = sls(blk[0], 11) + 128;
x8 = kW7 * (x4 + x5);
x4 = x8 + (kW1 - kW7) * x4;
x5 = x8 - (kW1 + kW7) * x5;
Expand Down Expand Up @@ -246,7 +248,7 @@ struct jpeg : decoder {

void columnIDCT(const int* blk, unsigned char *out, int stride) {
int x0, x1, x2, x3, x4, x5, x6, x7, x8;
if (!((x1 = u::sls(blk[8*4], 8))
if (!((x1 = sls(blk[8*4], 8))
| (x2 = blk[8*6]) | (x3 = blk[8*2])
| (x4 = blk[8*1]) | (x5 = blk[8*7])
| (x6 = blk[8*5]) | (x7 = blk[8*3])))
Expand All @@ -258,7 +260,7 @@ struct jpeg : decoder {
}
return;
}
x0 = u::sls(blk[0], 8) + 8192;
x0 = sls(blk[0], 8) + 8192;
x8 = kW7 * (x4 + x5) + 4;
x4 = (x8 + (kW1 - kW7) * x4) >> 3;
x5 = (x8 - (kW1 + kW7) * x5) >> 3;
Expand Down Expand Up @@ -296,14 +298,14 @@ struct jpeg : decoder {
return 0;
while (m_bufbits < bits) {
if (m_size <= 0) {
m_buf = u::sls(m_buf, 8) | 0xFF;
m_buf = sls(m_buf, 8) | 0xFF;
m_bufbits += 8;
continue;
}
newbyte = *m_position++;
m_size--;
m_bufbits += 8;
m_buf = u::sls(m_buf, 8) | newbyte;
m_buf = sls(m_buf, 8) | newbyte;
if (newbyte == 0xFF) {
if (m_size) {
unsigned char marker = *m_position++;
Expand All @@ -318,7 +320,7 @@ struct jpeg : decoder {
if ((marker & 0xF8) != 0xD0)
m_error = kMalformatted;
else {
m_buf = u::sls(m_buf, 8) | marker;
m_buf = sls(m_buf, 8) | marker;
m_bufbits += 8;
}
}
Expand Down Expand Up @@ -523,7 +525,7 @@ struct jpeg : decoder {
if (!(bits = value & 15))
return 0;
if ((value = getBits(bits)) < (1 << (bits - 1)))
value += u::sls(-1, bits) + 1;
value += sls(-1, bits) + 1;
return value;
}

Expand Down
36 changes: 25 additions & 11 deletions u_map.h
Expand Up @@ -35,10 +35,14 @@ class map {

const_iterator find(const K &key) const;
iterator find(const K &key);

pair<iterator, bool> insert(const pair<K, V> &p);
pair<iterator, bool> insert(pair<K, V> &&p);

void erase(const_iterator where);

V &operator[](const K &key);
V &operator[](K &&key);

void swap(map &other);

Expand Down Expand Up @@ -147,8 +151,13 @@ inline typename map<K, V>::const_iterator map<K, V>::find(const K &key) const {

template <typename K, typename V>
inline pair<typename map<K, V>::iterator, bool> map<K, V>::insert(const pair<K, V> &p) {
auto result = make_pair(find(p.first()), false);
if (result.first().node != 0)
return insert(u::move(pair<K, V>(p)));
}

template <typename K, typename V>
inline pair<typename map<K, V>::iterator, bool> map<K, V>::insert(pair<K, V> &&p) {
auto result = make_pair(find(p.first), false);
if (result.first.node != 0)
return result;

size_t nbuckets = (m_base.buckets.last - m_base.buckets.first);
Expand All @@ -158,29 +167,34 @@ inline pair<typename map<K, V>::iterator, bool> map<K, V>::insert(const pair<K,
nbuckets = (m_base.buckets.last - m_base.buckets.first);
}

size_t hh = hash(p.first()) & (nbuckets - 2);
typename map<K, V>::iterator &it = result.first();
const size_t hh = hash(p.first) & (nbuckets - 2);
typename map<K, V>::iterator &it = result.first;
it.node = detail::hash_insert_new(m_base, hh);

it.node->first.~hash_elem<K, V>();
new (&it.node->first) hash_elem<K, V>(p.first(), p.second());
new (&it.node->first) hash_elem<K, V>(u::move(p.first), u::move(p.second));

result.second() = true;
return result;
result.second = true;
return u::move(result);
}

template <typename K, typename V>
void map<K, V>::erase(const_iterator where) {
inline void map<K, V>::erase(const_iterator where) {
detail::hash_erase(m_base, where.node);
}

template <typename K, typename V>
V &map<K, V>::operator[](const K &key) {
return insert(make_pair(key, V())).first()->second;
inline V &map<K, V>::operator[](const K &key) {
return insert(u::move(make_pair(key, V()))).first->second;
}

template <typename K, typename V>
inline V &map<K, V>::operator[](K &&key) {
return insert(u::move(make_pair(u::forward<K>(key), V()))).first->second;
}

template <typename K, typename V>
void map<K, V>::swap(map &other) {
inline void map<K, V>::swap(map &other) {
detail::hash_swap(m_base, other.m_base);
}

Expand Down
7 changes: 0 additions & 7 deletions u_misc.h
Expand Up @@ -116,13 +116,6 @@ inline void print(const char *fmt, const Ts&... ts) {
fflush(stdout);
}

template <typename T>
inline typename enable_if<is_integral<T>::value && is_signed<T>::value,
typename make_signed<T>::type>::type
sls(T x, T n) {
return (typename make_signed<T>::type)((typename make_unsigned<T>::type)x << n);
}

void *moveMemory(void *dest, const void *src, size_t n);

// Random number generation facilities
Expand Down

0 comments on commit 6994571

Please sign in to comment.