Minor code cleanup

This commit is contained in:
Alex Szpakowski
2014-05-01 14:12:21 -03:00
parent e667485f68
commit e4dc533bb2
26 changed files with 112 additions and 110 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ public:
* Gets a pointer to the data. This pointer will obviously not
* be valid if the Data object is destroyed.
**/
virtual void *getData() const = 0 ;
virtual void *getData() const = 0;
/**
* Gets the size of the Data in bytes.
+10 -10
View File
@@ -26,7 +26,7 @@
namespace love
{
template<typename T, typename U, unsigned PEAK>
template<typename T, typename U, unsigned int PEAK>
class EnumMap
{
public:
@@ -37,14 +37,14 @@ public:
U u;
};
EnumMap(Entry *entries, unsigned size)
EnumMap(const Entry *entries, unsigned int size)
{
unsigned n = size/sizeof(Entry);
unsigned int n = size / sizeof(Entry);
for (unsigned i = 0; i<n; ++i)
for (unsigned int i = 0; i < n; ++i)
{
unsigned e_t = (unsigned)entries[i].t;
unsigned e_u = (unsigned)entries[i].u;
unsigned int e_t = (unsigned int) entries[i].t;
unsigned int e_u = (unsigned int) entries[i].u;
if (e_t < PEAK)
{
@@ -61,9 +61,9 @@ public:
bool find(T t, U &u)
{
if ((unsigned)t < PEAK && values_u[(unsigned)t].set)
if ((unsigned int) t < PEAK && values_u[(unsigned int) t].set)
{
u = (U)values_u[(unsigned)t].v;
u = (U) values_u[(unsigned int) t].v;
return true;
}
@@ -72,9 +72,9 @@ public:
bool find(U u, T &t)
{
if ((unsigned)u < PEAK && values_t[(unsigned)u].set)
if ((unsigned int) u < PEAK && values_t[(unsigned int) u].set)
{
t = (T)values_t[(unsigned)u].v;
t = (T) values_t[(unsigned int) u].v;
return true;
}
+20 -21
View File
@@ -26,7 +26,7 @@
namespace love
{
template<typename T, unsigned SIZE>
template<typename T, unsigned int SIZE>
class StringMap
{
public:
@@ -37,18 +37,16 @@ public:
T value;
};
StringMap(Entry *entries, unsigned num)
StringMap(const Entry *entries, unsigned int num)
{
for (unsigned i = 0; i < SIZE; ++i)
reverse[i] = 0;
for (unsigned int i = 0; i < SIZE; ++i)
reverse[i] = nullptr;
unsigned n = num/sizeof(Entry);
unsigned int n = num / sizeof(Entry);
for (unsigned i = 0; i < n; ++i)
{
for (unsigned int i = 0; i < n; ++i)
add(entries[i].key, entries[i].value);
}
}
bool streq(const char *a, const char *b)
@@ -57,6 +55,7 @@ public:
{
if (*a != *b)
return false;
++a;
++b;
}
@@ -66,11 +65,11 @@ public:
bool find(const char *key, T &t)
{
unsigned str_hash = djb2(key);
unsigned int str_hash = djb2(key);
for (unsigned i = 0; i < MAX; ++i)
for (unsigned int i = 0; i < MAX; ++i)
{
unsigned str_i = (str_hash + i) % MAX;
unsigned int str_i = (str_hash + i) % MAX;
if (!records[str_i].set)
return false;
@@ -85,14 +84,14 @@ public:
return false;
}
bool find(T key, const char *&str)
bool find(T key, const char *&str)
{
unsigned index = (unsigned)key;
unsigned int index = (unsigned int) key;
if (index >= SIZE)
return false;
if (reverse[index] != 0)
if (reverse[index] != nullptr)
{
str = reverse[index];
return true;
@@ -105,12 +104,12 @@ public:
bool add(const char *key, T value)
{
unsigned str_hash = djb2(key);
unsigned int str_hash = djb2(key);
bool inserted = false;
for (unsigned i = 0; i < MAX; ++i)
for (unsigned int i = 0; i < MAX; ++i)
{
unsigned str_i = (str_hash + i) % MAX;
unsigned int str_i = (str_hash + i) % MAX;
if (!records[str_i].set)
{
@@ -122,7 +121,7 @@ public:
}
}
unsigned index = (unsigned)value;
unsigned int index = (unsigned int) value;
if (index >= SIZE)
{
@@ -135,9 +134,9 @@ public:
return inserted;
}
unsigned djb2(const char *key)
unsigned int djb2(const char *key)
{
unsigned hash = 5381;
unsigned int hash = 5381;
int c;
while ((c = *key++))
@@ -156,7 +155,7 @@ private:
Record() : set(false) {}
};
const static unsigned MAX = SIZE*2;
static const unsigned int MAX = SIZE * 2;
Record records[MAX];
const char *reverse[SIZE];
+11 -24
View File
@@ -21,11 +21,10 @@
#ifndef LOVE_INT_H
#define LOVE_INT_H
#include "common/config.h"
#ifndef LOVE_WINDOWS
// C standard sized integer types.
// This header was added to Visual studio in VS 2012, which is LOVE's current
// minimum supported VS version (as of this comment's commit date.)
#include <stdint.h>
#endif
#define LOVE_INT8_MAX 0x7F
#define LOVE_UINT8_MAX 0xFF
@@ -39,26 +38,14 @@
namespace love
{
// Blame Microsoft
#ifdef LOVE_WINDOWS
typedef __int8 int8;
typedef unsigned __int8 uint8;
typedef __int16 int16;
typedef unsigned __int16 uint16;
typedef __int32 int32;
typedef unsigned __int32 uint32;
typedef __int64 int64;
typedef unsigned __int64 uint64;
#else // LOVE_WINDOWS
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
#endif // LOVE_WINDOWS
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
} // love