Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-10-22 07:25:53 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-22 07:25:53 +0400
commita4b27831693eed988bcdf957bbe9ad7609e7bdf7 (patch)
tree3494d520b807cf40ebfc32650b67e32e5287f723 /intern/container
parent226a5ee83446f91cfeccc73912de85e89fe2169f (diff)
small optimization for BLI_heap(), give some speedup in decimeter.
- use unsigned ints only (where mixing signed/unsigned) - turn heap_swap into an inline function, add SWAP_TVAL macro to swap values using a temp value as storage. - added type checking SHIFT3/4 macros also style cleanup for CTR_Map
Diffstat (limited to 'intern/container')
-rw-r--r--intern/container/CTR_HashedPtr.h17
-rw-r--r--intern/container/CTR_Map.h76
2 files changed, 51 insertions, 42 deletions
diff --git a/intern/container/CTR_HashedPtr.h b/intern/container/CTR_HashedPtr.h
index 8d0ad2bb2a3..b7ac460f270 100644
--- a/intern/container/CTR_HashedPtr.h
+++ b/intern/container/CTR_HashedPtr.h
@@ -43,12 +43,19 @@ inline unsigned int CTR_Hash(void *inDWord)
class CTR_HashedPtr
{
- void* m_valptr;
+ void *m_valptr;
public:
- CTR_HashedPtr(void* val) : m_valptr(val) {};
- unsigned int hash() const { return CTR_Hash(m_valptr);};
- inline friend bool operator ==(const CTR_HashedPtr & rhs, const CTR_HashedPtr & lhs) { return rhs.m_valptr == lhs.m_valptr;};
- void *getValue() const { return m_valptr; }
+ CTR_HashedPtr(void *val) : m_valptr(val) {
+ };
+ unsigned int hash() const {
+ return CTR_Hash(m_valptr);
+ };
+ inline friend bool operator ==(const CTR_HashedPtr & rhs, const CTR_HashedPtr & lhs) {
+ return rhs.m_valptr == lhs.m_valptr;
+ };
+ void *getValue() const {
+ return m_valptr;
+ }
};
#endif /* __CTR_HASHEDPTR_H__ */
diff --git a/intern/container/CTR_Map.h b/intern/container/CTR_Map.h
index d729f2a1b06..c278fe5330c 100644
--- a/intern/container/CTR_Map.h
+++ b/intern/container/CTR_Map.h
@@ -37,13 +37,14 @@ class CTR_Map {
private:
struct Entry {
Entry (Entry *next, Key key, Value value) :
- m_next(next),
- m_key(key),
- m_value(value) {}
+ m_next(next),
+ m_key(key),
+ m_value(value) {
+ }
Entry *m_next;
- Key m_key;
- Value m_value;
+ Key m_key;
+ Value m_value;
};
public:
@@ -62,18 +63,18 @@ public:
for (int i = 0; i < m_num_buckets; ++i) {
m_buckets[i] = 0;
- for (Entry *entry = map.m_buckets[i]; entry; entry=entry->m_next)
+ for (Entry *entry = map.m_buckets[i]; entry; entry = entry->m_next) {
insert(entry->m_key, entry->m_value);
+ }
}
}
- int size() {
- int count=0;
- for (int i=0;i<m_num_buckets;i++)
- {
- Entry* bucket = m_buckets[i];
- while(bucket)
- {
+ int size()
+ {
+ int count = 0;
+ for (int i = 0; i < m_num_buckets; i++) {
+ Entry *bucket = m_buckets[i];
+ while (bucket) {
bucket = bucket->m_next;
count++;
}
@@ -81,15 +82,13 @@ public:
return count;
}
- Value* at(int index) {
- int count=0;
- for (int i=0;i<m_num_buckets;i++)
- {
- Entry* bucket = m_buckets[i];
- while(bucket)
- {
- if (count==index)
- {
+ Value *at(int index)
+ {
+ int count = 0;
+ for (int i = 0; i < m_num_buckets; i++) {
+ Entry *bucket = m_buckets[i];
+ while (bucket) {
+ if (count == index) {
return &bucket->m_value;
}
bucket = bucket->m_next;
@@ -99,15 +98,13 @@ public:
return 0;
}
- Key* getKey(int index) {
- int count=0;
- for (int i=0;i<m_num_buckets;i++)
- {
- Entry* bucket = m_buckets[i];
- while(bucket)
- {
- if (count==index)
- {
+ Key *getKey(int index)
+ {
+ int count = 0;
+ for (int i = 0; i < m_num_buckets; i++) {
+ Entry *bucket = m_buckets[i];
+ while (bucket) {
+ if (count == index) {
return &bucket->m_key;
}
bucket = bucket->m_next;
@@ -117,7 +114,8 @@ public:
return 0;
}
- void clear() {
+ void clear()
+ {
for (int i = 0; i < m_num_buckets; ++i) {
Entry *entry_ptr = m_buckets[i];
@@ -130,12 +128,14 @@ public:
}
}
- ~CTR_Map() {
+ ~CTR_Map()
+ {
clear();
- delete [] m_buckets;
+ delete[] m_buckets;
}
- void insert(const Key& key, const Value& value) {
+ void insert(const Key& key, const Value& value)
+ {
Entry *entry_ptr = m_buckets[key.hash() % m_num_buckets];
while ((entry_ptr != 0) && !(key == entry_ptr->m_key)) {
entry_ptr = entry_ptr->m_next;
@@ -150,7 +150,8 @@ public:
}
}
- void remove(const Key& key) {
+ void remove(const Key& key)
+ {
Entry **entry_ptr = &m_buckets[key.hash() % m_num_buckets];
while ((*entry_ptr != 0) && !(key == (*entry_ptr)->m_key)) {
entry_ptr = &(*entry_ptr)->m_next;
@@ -163,7 +164,8 @@ public:
}
}
- Value *operator[](Key key) {
+ Value *operator[](Key key)
+ {
Entry *bucket = m_buckets[key.hash() % m_num_buckets];
while ((bucket != 0) && !(key == bucket->m_key)) {
bucket = bucket->m_next;