diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-dictionary.h | 1501 | ||||
| -rw-r--r-- | source/core/slang-file-system.cpp | 22 | ||||
| -rw-r--r-- | source/core/slang-implicit-directory-collector.cpp | 4 | ||||
| -rw-r--r-- | source/core/slang-io.cpp | 4 | ||||
| -rw-r--r-- | source/core/slang-linked-list.h | 112 | ||||
| -rw-r--r-- | source/core/slang-memory-file-system.cpp | 12 | ||||
| -rw-r--r-- | source/core/slang-platform.cpp | 2 | ||||
| -rw-r--r-- | source/core/slang-riff-file-system.cpp | 4 | ||||
| -rw-r--r-- | source/core/slang-rtti-info.cpp | 6 | ||||
| -rw-r--r-- | source/core/slang-rtti-util.cpp | 3 | ||||
| -rw-r--r-- | source/core/slang-string-slice-index-map.h | 4 | ||||
| -rw-r--r-- | source/core/slang-string-slice-pool.cpp | 16 | ||||
| -rw-r--r-- | source/core/slang-string.h | 2 | ||||
| -rw-r--r-- | source/core/slang-token-reader.cpp | 14 | ||||
| -rw-r--r-- | source/core/slang-token-reader.h | 2 |
15 files changed, 851 insertions, 857 deletions
diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h index 0839a649c..0350a99d2 100644 --- a/source/core/slang-dictionary.h +++ b/source/core/slang-dictionary.h @@ -11,678 +11,670 @@ namespace Slang { - template<typename TKey, typename TValue> - class KeyValuePair - { - public: - TKey Key; - TValue Value; - KeyValuePair() - {} - KeyValuePair(const TKey & key, const TValue & value) - { - Key = key; - Value = value; - } - KeyValuePair(TKey && key, TValue && value) - { - Key = _Move(key); - Value = _Move(value); - } - KeyValuePair(TKey && key, const TValue & value) - { - Key = _Move(key); - Value = value; - } - KeyValuePair(const KeyValuePair<TKey, TValue> & _that) - { - Key = _that.Key; - Value = _that.Value; - } - KeyValuePair(KeyValuePair<TKey, TValue> && _that) - { - operator=(_Move(_that)); - } - KeyValuePair & operator=(KeyValuePair<TKey, TValue> && that) - { - Key = _Move(that.Key); - Value = _Move(that.Value); - return *this; - } - KeyValuePair & operator=(const KeyValuePair<TKey, TValue> & that) - { - Key = that.Key; - Value = that.Value; - return *this; - } - HashCode getHashCode() - { + template<typename TKey, typename TValue> + class KeyValuePair + { + public: + TKey key; + TValue value; + KeyValuePair() + {} + KeyValuePair(const TKey& inKey, const TValue& inValue) + { + key = inKey; + value = inValue; + } + KeyValuePair(TKey&& inKey, TValue&& inValue) + { + key = _Move(inKey); + value = _Move(inValue); + } + KeyValuePair(TKey&& inKey, const TValue& inValue) + { + key = _Move(inKey); + value = inValue; + } + KeyValuePair(const KeyValuePair<TKey, TValue>& that) + { + key = that.key; + value = that.value; + } + KeyValuePair(KeyValuePair<TKey, TValue>&& that) + { + operator=(_Move(that)); + } + KeyValuePair& operator=(KeyValuePair<TKey, TValue>&& that) + { + key = _Move(that.key); + value = _Move(that.value); + return *this; + } + KeyValuePair& operator=(const KeyValuePair<TKey, TValue>& that) + { + key = that.key; + value = that.value; + return *this; + } + HashCode getHashCode() + { return combineHash( - Slang::getHashCode(Key), - Slang::getHashCode(Value)); - } + Slang::getHashCode(key), + Slang::getHashCode(value)); + } bool operator==(const KeyValuePair<TKey, TValue>& that) const { - return (Key == that.Key) && (Value == that.Value); + return (key == that.key) && (value == that.value); } - }; + }; - template<typename TKey, typename TValue> - inline KeyValuePair<TKey, TValue> KVPair(const TKey & k, const TValue & v) - { - return KeyValuePair<TKey, TValue>(k, v); - } + template<typename TKey, typename TValue> + inline KeyValuePair<TKey, TValue> KVPair(const TKey& k, const TValue& v) + { + return KeyValuePair<TKey, TValue>(k, v); + } - const float MaxLoadFactor = 0.7f; + const float kMaxLoadFactor = 0.7f; - template<typename TKey, typename TValue> - class Dictionary - { - friend class Iterator; - friend class ItemProxy; + template<typename TKey, typename TValue> + class Dictionary + { + friend class Iterator; + friend class ItemProxy; public: typedef TValue ValueType; typedef TKey KeyType; - typedef Dictionary ThisType; - private: - inline int GetProbeOffset(int /*probeId*/) const - { - // linear probing - return 1; - } - private: - int bucketSizeMinusOne; - int _count; - UIntSet marks; - KeyValuePair<TKey, TValue>* hashMap; - void Free() - { - if (hashMap) - delete[] hashMap; - hashMap = 0; - } - inline bool IsDeleted(int pos) const - { - return marks.contains((pos << 1) + 1); - } - inline bool IsEmpty(int pos) const - { - return !marks.contains((pos << 1)); - } - inline void SetDeleted(int pos, bool val) - { - if (val) - marks.add((pos << 1) + 1); - else - marks.remove((pos << 1) + 1); - } - inline void SetEmpty(int pos, bool val) - { - if (val) - marks.remove((pos << 1)); - else - marks.add((pos << 1)); - } - struct FindPositionResult - { - int ObjectPosition; - int InsertionPosition; - FindPositionResult() - { - ObjectPosition = -1; - InsertionPosition = -1; - } - FindPositionResult(int objPos, int insertPos) - { - ObjectPosition = objPos; - InsertionPosition = insertPos; - } + typedef Dictionary ThisType; + private: + inline int getProbeOffset(int /*probeId*/) const + { + // linear probing + return 1; + } + private: + int m_bucketCountMinusOne; + int m_count; + UIntSet m_marks; + KeyValuePair<TKey, TValue>* m_hashMap; + void deallocateAll() + { + if (m_hashMap) + delete[] m_hashMap; + m_hashMap = nullptr; + } + inline bool isDeleted(int pos) const + { + return m_marks.contains((pos << 1) + 1); + } + inline bool isEmpty(int pos) const + { + return !m_marks.contains((pos << 1)); + } + inline void setDeleted(int pos, bool val) + { + if (val) + m_marks.add((pos << 1) + 1); + else + m_marks.remove((pos << 1) + 1); + } + inline void setEmpty(int pos, bool val) + { + if (val) + m_marks.remove((pos << 1)); + else + m_marks.add((pos << 1)); + } + struct FindPositionResult + { + int objectPosition; + int insertionPosition; - }; + FindPositionResult() + { + objectPosition = -1; + insertionPosition = -1; + } + FindPositionResult(int objPos, int insertPos) + { + objectPosition = objPos; + insertionPosition = insertPos; + } + }; template<typename KeyType> - inline int GetHashPos(KeyType& key) const + inline int getHashPos(KeyType& key) const { - SLANG_ASSERT(bucketSizeMinusOne > 0); + SLANG_ASSERT(m_bucketCountMinusOne > 0); const unsigned int hash = (unsigned int)getHashCode(key); - return (hash * 2654435761u) % (unsigned int)(bucketSizeMinusOne); - } + return (hash * 2654435761u) % (unsigned int)(m_bucketCountMinusOne); + } template<typename KeyType> - FindPositionResult FindPosition(const KeyType& key) const - { - int hashPos = GetHashPos(const_cast<KeyType&>(key)); - int insertPos = -1; - int numProbes = 0; - while (numProbes <= bucketSizeMinusOne) - { - if (IsEmpty(hashPos)) - { - if (insertPos == -1) - return FindPositionResult(-1, hashPos); - else - return FindPositionResult(-1, insertPos); - } - else if (IsDeleted(hashPos)) - { - if (insertPos == -1) - insertPos = hashPos; - } - else if (hashMap[hashPos].Key == key) - { - return FindPositionResult(hashPos, -1); - } - numProbes++; - hashPos = (hashPos + GetProbeOffset(numProbes)) & bucketSizeMinusOne; - } - if (insertPos != -1) - return FindPositionResult(-1, insertPos); - SLANG_ASSERT_FAILURE("Hash map is full. This indicates an error in Key::Equal or Key::getHashCode."); - } - TValue & _Insert(KeyValuePair<TKey, TValue>&& kvPair, int pos) - { - hashMap[pos] = _Move(kvPair); - SetEmpty(pos, false); - SetDeleted(pos, false); - return hashMap[pos].Value; - } - void Rehash() - { - if (bucketSizeMinusOne == -1 || _count >= int(MaxLoadFactor * bucketSizeMinusOne)) - { - int newSize = (bucketSizeMinusOne + 1) * 2; - if (newSize == 0) - { - newSize = 16; - } - Dictionary<TKey, TValue> newDict; - newDict.bucketSizeMinusOne = newSize - 1; - newDict.hashMap = new KeyValuePair<TKey, TValue>[newSize]; - newDict.marks.resizeAndClear(newSize * 2); - if (hashMap) - { - for (auto & kvPair : *this) - { - newDict.Add(_Move(kvPair)); - } - } - *this = _Move(newDict); - } - } + FindPositionResult findPosition(const KeyType& key) const + { + int hashPos = getHashPos(const_cast<KeyType&>(key)); + int insertPos = -1; + int numProbes = 0; + while (numProbes <= m_bucketCountMinusOne) + { + if (isEmpty(hashPos)) + { + if (insertPos == -1) + return FindPositionResult(-1, hashPos); + else + return FindPositionResult(-1, insertPos); + } + else if (isDeleted(hashPos)) + { + if (insertPos == -1) + insertPos = hashPos; + } + else if (m_hashMap[hashPos].key == key) + { + return FindPositionResult(hashPos, -1); + } + numProbes++; + hashPos = (hashPos + getProbeOffset(numProbes)) & m_bucketCountMinusOne; + } + if (insertPos != -1) + return FindPositionResult(-1, insertPos); + SLANG_ASSERT_FAILURE("Hash map is full. This indicates an error in Key::Equal or Key::getHashCode."); + } + TValue& _insert(KeyValuePair<TKey, TValue>&& kvPair, int pos) + { + m_hashMap[pos] = _Move(kvPair); + setEmpty(pos, false); + setDeleted(pos, false); + return m_hashMap[pos].value; + } + void maybeRehash() + { + if (m_bucketCountMinusOne == -1 || m_count >= int(kMaxLoadFactor * m_bucketCountMinusOne)) + { + int newSize = (m_bucketCountMinusOne + 1) * 2; + if (newSize == 0) + { + newSize = 16; + } + Dictionary<TKey, TValue> newDict; + newDict.m_bucketCountMinusOne = newSize - 1; + newDict.m_hashMap = new KeyValuePair<TKey, TValue>[newSize]; + newDict.m_marks.resizeAndClear(newSize * 2); + if (m_hashMap) + { + for (auto& kvPair : *this) + { + newDict.add(_Move(kvPair)); + } + } + *this = _Move(newDict); + } + } - bool AddIfNotExists(KeyValuePair<TKey, TValue>&& kvPair) - { - Rehash(); - auto pos = FindPosition(kvPair.Key); - if (pos.ObjectPosition != -1) - return false; - else if (pos.InsertionPosition != -1) - { - _count++; - _Insert(_Move(kvPair), pos.InsertionPosition); - return true; - } - else - SLANG_ASSERT_FAILURE("Inconsistent find result returned. This is a bug in Dictionary implementation."); - } - void Add(KeyValuePair<TKey, TValue>&& kvPair) - { - if (!AddIfNotExists(_Move(kvPair))) + bool addIfNotExists(KeyValuePair<TKey, TValue>&& kvPair) + { + maybeRehash(); + auto pos = findPosition(kvPair.key); + if (pos.objectPosition != -1) + return false; + else if (pos.insertionPosition != -1) + { + m_count++; + _insert(_Move(kvPair), pos.insertionPosition); + return true; + } + else + SLANG_ASSERT_FAILURE("Inconsistent find result returned. This is a bug in Dictionary implementation."); + } + void add(KeyValuePair<TKey, TValue>&& kvPair) + { + if (!addIfNotExists(_Move(kvPair))) SLANG_ASSERT_FAILURE("The key already exists in Dictionary."); - } - TValue& Set(KeyValuePair<TKey, TValue>&& kvPair) - { - Rehash(); - auto pos = FindPosition(kvPair.Key); - if (pos.ObjectPosition != -1) - return _Insert(_Move(kvPair), pos.ObjectPosition); - else if (pos.InsertionPosition != -1) - { - _count++; - return _Insert(_Move(kvPair), pos.InsertionPosition); - } - else + } + TValue& set(KeyValuePair<TKey, TValue>&& kvPair) + { + maybeRehash(); + auto pos = findPosition(kvPair.key); + if (pos.objectPosition != -1) + return _insert(_Move(kvPair), pos.objectPosition); + else if (pos.insertionPosition != -1) + { + m_count++; + return _insert(_Move(kvPair), pos.insertionPosition); + } + else SLANG_ASSERT_FAILURE("Inconsistent find result returned. This is a bug in Dictionary implementation."); - } - public: - class Iterator - { - private: - const Dictionary<TKey, TValue> * dict; - int pos; - public: - KeyValuePair<TKey, TValue> & operator *() const - { - return dict->hashMap[pos]; - } - KeyValuePair<TKey, TValue> * operator ->() const - { - return dict->hashMap + pos; - } - Iterator & operator ++() - { - if (pos > dict->bucketSizeMinusOne) - return *this; - pos++; - while (pos <= dict->bucketSizeMinusOne && (dict->IsDeleted(pos) || dict->IsEmpty(pos))) - { - pos++; - } - return *this; - } - Iterator operator ++(int) - { - Iterator rs = *this; - operator++(); - return rs; - } - bool operator != (const Iterator & _that) const - { - return pos != _that.pos || dict != _that.dict; - } - bool operator == (const Iterator & _that) const - { - return pos == _that.pos && dict == _that.dict; - } - Iterator(const Dictionary<TKey, TValue> * _dict, int _pos) - { - this->dict = _dict; - this->pos = _pos; - } - Iterator() - { - this->dict = 0; - this->pos = 0; - } - }; - - Iterator begin() const - { - int pos = 0; - while (pos < bucketSizeMinusOne + 1) - { - if (IsEmpty(pos) || IsDeleted(pos)) - pos++; - else - break; - } - return Iterator(this, pos); - } - Iterator end() const - { - return Iterator(this, bucketSizeMinusOne + 1); - } - public: - void Add(const TKey & key, const TValue & value) - { - Add(KeyValuePair<TKey, TValue>(key, value)); - } - void Add(TKey && key, TValue && value) - { - Add(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); - } - bool AddIfNotExists(const TKey & key, const TValue & value) - { - return AddIfNotExists(KeyValuePair<TKey, TValue>(key, value)); - } - bool AddIfNotExists(TKey && key, TValue && value) - { - return AddIfNotExists(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); - } - void Remove(const TKey & key) - { - if (_count == 0) - return; - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) - { - SetDeleted(pos.ObjectPosition, true); - _count--; - } - } - void Clear() - { - _count = 0; + } + public: + class Iterator + { + private: + const Dictionary<TKey, TValue>* dict; + int pos; + public: + KeyValuePair<TKey, TValue>& operator*() const + { + return dict->m_hashMap[pos]; + } + KeyValuePair<TKey, TValue>* operator->() const + { + return dict->m_hashMap + pos; + } + Iterator& operator++() + { + if (pos > dict->m_bucketCountMinusOne) + return *this; + pos++; + while (pos <= dict->m_bucketCountMinusOne && (dict->isDeleted(pos) || dict->isEmpty(pos))) + { + pos++; + } + return *this; + } + Iterator operator++(int) + { + Iterator rs = *this; + operator++(); + return rs; + } + bool operator!=(const Iterator& that) const + { + return pos != that.pos || dict != that.dict; + } + bool operator==(const Iterator& that) const + { + return pos == that.pos && dict == that.dict; + } + Iterator(const Dictionary<TKey, TValue>* inDict, int inPos) + { + this->dict = inDict; + this->pos = inPos; + } + Iterator() + { + this->dict = nullptr; + this->pos = 0; + } + }; - marks.clear(); - } + Iterator begin() const + { + int pos = 0; + while (pos < m_bucketCountMinusOne + 1) + { + if (isEmpty(pos) || isDeleted(pos)) + pos++; + else + break; + } + return Iterator(this, pos); + } + Iterator end() const + { + return Iterator(this, m_bucketCountMinusOne + 1); + } + public: + void add(const TKey& key, const TValue& value) + { + add(KeyValuePair<TKey, TValue>(key, value)); + } + void add(TKey&& key, TValue&& value) + { + add(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); + } + bool addIfNotExists(const TKey& key, const TValue& value) + { + return addIfNotExists(KeyValuePair<TKey, TValue>(key, value)); + } + bool addIfNotExists(TKey&& key, TValue&& value) + { + return addIfNotExists(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); + } + void remove(const TKey& key) + { + if (m_count == 0) + return; + auto pos = findPosition(key); + if (pos.objectPosition != -1) + { + setDeleted(pos.objectPosition, true); + m_count--; + } + } + void clear() + { + m_count = 0; + m_marks.clear(); + } - TValue* TryGetValueOrAdd(const TKey& key, const TValue& value) + TValue* tryGetValueOrAdd(const TKey& key, const TValue& value) { - Rehash(); - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) + maybeRehash(); + auto pos = findPosition(key); + if (pos.objectPosition != -1) { - return &hashMap[pos.ObjectPosition].Value; + return &m_hashMap[pos.objectPosition].value; } - else if (pos.InsertionPosition != -1) + else if (pos.insertionPosition != -1) { // Make pair KeyValuePair<TKey, TValue> kvPair(_Move(key), _Move(value)); - _count++; - _Insert(_Move(kvPair), pos.InsertionPosition); + m_count++; + _insert(_Move(kvPair), pos.insertionPosition); return nullptr; } else SLANG_ASSERT_FAILURE("Inconsistent find result returned. This is a bug in Dictionary implementation."); } - /// This differs from TryGetValueOrAdd, in that it always returns the Value held in the Dictionary. + /// This differs from tryGetValueOrAdd, in that it always returns the Value held in the Dictionary. /// If there isn't already an entry for 'key', a value is added with defaultValue. - TValue& GetOrAddValue(const TKey& key, const TValue& defaultValue) + TValue& getOrAddValue(const TKey& key, const TValue& defaultValue) { - Rehash(); - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) + maybeRehash(); + auto pos = findPosition(key); + if (pos.objectPosition != -1) { - return hashMap[pos.ObjectPosition].Value; + return m_hashMap[pos.objectPosition].value; } - else if (pos.InsertionPosition != -1) + else if (pos.insertionPosition != -1) { // Make pair KeyValuePair<TKey, TValue> kvPair(_Move(key), _Move(defaultValue)); - _count++; - return _Insert(_Move(kvPair), pos.InsertionPosition); + m_count++; + return _insert(_Move(kvPair), pos.insertionPosition); } else SLANG_ASSERT_FAILURE("Inconsistent find result returned. This is a bug in Dictionary implementation."); } - void Set(const TKey& key, const TValue& value) - { - if (auto ptr = TryGetValueOrAdd(key, value)) - { - *ptr = value; - } - } + void set(const TKey& key, const TValue& value) + { + if (auto ptr = tryGetValueOrAdd(key, value)) + { + *ptr = value; + } + } template<typename KeyType> - bool ContainsKey(const KeyType& key) const - { - if (bucketSizeMinusOne == -1) - return false; - auto pos = FindPosition(key); - return pos.ObjectPosition != -1; - } + bool containsKey(const KeyType& key) const + { + if (m_bucketCountMinusOne == -1) + return false; + auto pos = findPosition(key); + return pos.objectPosition != -1; + } template<typename KeyType> - bool TryGetValue(const KeyType& key, TValue& value) const - { - if (bucketSizeMinusOne == -1) - return false; - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) - { - value = hashMap[pos.ObjectPosition].Value; - return true; - } - return false; - } + bool tryGetValue(const KeyType& key, TValue& value) const + { + if (m_bucketCountMinusOne == -1) + return false; + auto pos = findPosition(key); + if (pos.objectPosition != -1) + { + value = m_hashMap[pos.objectPosition].value; + return true; + } + return false; + } template<typename KeyType> - TValue* TryGetValue(const KeyType& key) const - { - if (bucketSizeMinusOne == -1) - return nullptr; - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) - { - return &hashMap[pos.ObjectPosition].Value; - } - return nullptr; - } + TValue* tryGetValue(const KeyType& key) const + { + if (m_bucketCountMinusOne == -1) + return nullptr; + auto pos = findPosition(key); + if (pos.objectPosition != -1) + { + return &m_hashMap[pos.objectPosition].value; + } + return nullptr; + } - class ItemProxy - { - private: - const Dictionary<TKey, TValue> * dict; - TKey key; - public: - ItemProxy(const TKey& _key, const Dictionary<TKey, TValue>* _dict) - { - this->dict = _dict; - this->key = _key; - } - ItemProxy(TKey&& _key, const Dictionary<TKey, TValue>* _dict) - { - this->dict = _dict; - this->key = _Move(_key); - } - TValue & GetValue() const - { - auto pos = dict->FindPosition(key); - if (pos.ObjectPosition != -1) - { - return dict->hashMap[pos.ObjectPosition].Value; - } - else + class ItemProxy + { + private: + const Dictionary<TKey, TValue>* dict; + TKey key; + public: + ItemProxy(const TKey& _key, const Dictionary<TKey, TValue>* _dict) + { + this->dict = _dict; + this->key = _key; + } + ItemProxy(TKey&& _key, const Dictionary<TKey, TValue>* _dict) + { + this->dict = _dict; + this->key = _Move(_key); + } + TValue& getValue() const + { + auto pos = dict->findPosition(key); + if (pos.objectPosition != -1) + { + return dict->m_hashMap[pos.objectPosition].value; + } + else SLANG_ASSERT_FAILURE("The key does not exist in dictionary."); - } - inline TValue & operator()() const - { - return GetValue(); - } - operator TValue&() const - { - return GetValue(); - } - TValue & operator = (const TValue & val) const - { - return ((Dictionary<TKey, TValue>*)dict)->Set(KeyValuePair<TKey, TValue>(_Move(key), val)); - } - TValue & operator = (TValue && val) const - { - return ((Dictionary<TKey, TValue>*)dict)->Set(KeyValuePair<TKey, TValue>(_Move(key), _Move(val))); - } - }; - ItemProxy operator [](const TKey & key) const - { - return ItemProxy(key, this); - } - ItemProxy operator [](TKey && key) const - { - return ItemProxy(_Move(key), this); - } - int Count() const - { - return _count; - } + } + inline TValue& operator()() const + { + return getValue(); + } + operator TValue&() const + { + return getValue(); + } + TValue& operator=(const TValue& val) const + { + return ((Dictionary<TKey, TValue>*)dict)->set(KeyValuePair<TKey, TValue>(_Move(key), val)); + } + TValue& operator=(TValue&& val) const + { + return ((Dictionary<TKey, TValue>*)dict)->set(KeyValuePair<TKey, TValue>(_Move(key), _Move(val))); + } + }; + ItemProxy operator[](const TKey& key) const + { + return ItemProxy(key, this); + } + ItemProxy operator[](TKey&& key) const + { + return ItemProxy(_Move(key), this); + } + int getCount() const + { + return m_count; + } - /// Swap this with rhs - void swapWith(ThisType& rhs); + /// Swap this with rhs + void swapWith(ThisType& rhs); - private: - template<typename... Args> - void Init(const KeyValuePair<TKey, TValue> & kvPair, Args... args) - { - Add(kvPair); - Init(args...); - } - public: - Dictionary() - { - bucketSizeMinusOne = -1; - _count = 0; - hashMap = nullptr; - } - template<typename Arg, typename... Args> - Dictionary(Arg arg, Args... args) - { - Init(arg, args...); - } - Dictionary(const Dictionary<TKey, TValue>& other) - : bucketSizeMinusOne(-1), _count(0), hashMap(nullptr) - { - *this = other; - } - Dictionary(Dictionary<TKey, TValue>&& other) - : bucketSizeMinusOne(-1), _count(0), hashMap(nullptr) - { - *this = (_Move(other)); - } - Dictionary<TKey, TValue>& operator = (const Dictionary<TKey, TValue>& other) - { - if (this == &other) - return *this; - Free(); - bucketSizeMinusOne = other.bucketSizeMinusOne; - _count = other._count; - hashMap = new KeyValuePair<TKey, TValue>[other.bucketSizeMinusOne + 1]; - marks = other.marks; - for (int i = 0; i <= bucketSizeMinusOne; i++) - hashMap[i] = other.hashMap[i]; - return *this; - } - Dictionary<TKey, TValue> & operator = (Dictionary<TKey, TValue>&& other) - { - if (this == &other) - return *this; - Free(); - bucketSizeMinusOne = other.bucketSizeMinusOne; - _count = other._count; - hashMap = other.hashMap; - marks = _Move(other.marks); - other.hashMap = 0; - other._count = 0; - other.bucketSizeMinusOne = -1; - return *this; - } - ~Dictionary() - { - Free(); - } - }; + private: + template<typename... Args> + void init(const KeyValuePair<TKey, TValue>& kvPair, Args... args) + { + add(kvPair); + init(args...); + } + public: + Dictionary() + { + m_bucketCountMinusOne = -1; + m_count = 0; + m_hashMap = nullptr; + } + template<typename Arg, typename... Args> + Dictionary(Arg arg, Args... args) + { + init(arg, args...); + } + Dictionary(const Dictionary<TKey, TValue>& other) + : m_bucketCountMinusOne(-1), m_count(0), m_hashMap(nullptr) + { + *this = other; + } + Dictionary(Dictionary<TKey, TValue>&& other) + : m_bucketCountMinusOne(-1), m_count(0), m_hashMap(nullptr) + { + *this = (_Move(other)); + } + Dictionary<TKey, TValue>& operator=(const Dictionary<TKey, TValue>& other) + { + if (this == &other) + return *this; + deallocateAll(); + m_bucketCountMinusOne = other.m_bucketCountMinusOne; + m_count = other.m_count; + m_hashMap = new KeyValuePair<TKey, TValue>[other.m_bucketCountMinusOne + 1]; + m_marks = other.m_marks; + for (int i = 0; i <= m_bucketCountMinusOne; i++) + m_hashMap[i] = other.m_hashMap[i]; + return *this; + } + Dictionary<TKey, TValue>& operator=(Dictionary<TKey, TValue>&& other) + { + if (this == &other) + return *this; + deallocateAll(); + m_bucketCountMinusOne = other.m_bucketCountMinusOne; + m_count = other.m_count; + m_hashMap = other.m_hashMap; + m_marks = _Move(other.m_marks); + other.m_hashMap = nullptr; + other.m_count = 0; + other.m_bucketCountMinusOne = -1; + return *this; + } + ~Dictionary() + { + deallocateAll(); + } + }; - // --------------------------------------------------------- - template<typename TKey, typename TValue> - void Dictionary<TKey, TValue>::swapWith(ThisType& rhs) - { - Swap(bucketSizeMinusOne, rhs.bucketSizeMinusOne); - Swap(_count, rhs._count); - marks.swapWith(rhs.marks); - Swap(hashMap, rhs.hashMap); - } + // --------------------------------------------------------- + template<typename TKey, typename TValue> + void Dictionary<TKey, TValue>::swapWith(ThisType& rhs) + { + Swap(m_bucketCountMinusOne, rhs.m_bucketCountMinusOne); + Swap(m_count, rhs.m_count); + m_marks.swapWith(rhs.m_marks); + Swap(m_hashMap, rhs.m_hashMap); + } - class _DummyClass - {}; + /* We may want to rename this, as strictly speaking _Caps names are reserved */ + class _DummyClass + {}; - template<typename T, typename DictionaryType> - class HashSetBase - { - protected: - DictionaryType dict; - private: - template<typename... Args> - void Init(const T & v, Args... args) - { - Add(v); - Init(args...); - } - public: - HashSetBase() - {} - template<typename Arg, typename... Args> - HashSetBase(Arg arg, Args... args) - { - Init(arg, args...); - } - HashSetBase(const HashSetBase & set) - { - operator=(set); - } - HashSetBase(HashSetBase && set) - { - operator=(_Move(set)); - } - HashSetBase & operator = (const HashSetBase & set) - { - dict = set.dict; - return *this; - } - HashSetBase & operator = (HashSetBase && set) - { - dict = _Move(set.dict); - return *this; - } - public: - class Iterator - { - private: - typename DictionaryType::Iterator iter; - public: - Iterator() = default; - T & operator *() const - { - return (*iter).Key; - } - T * operator ->() const - { - return &(*iter).Key; - } - Iterator & operator ++() - { - ++iter; - return *this; - } - Iterator operator ++(int) - { - Iterator rs = *this; - operator++(); - return rs; - } - bool operator != (const Iterator & _that) const - { - return iter != _that.iter; - } - bool operator == (const Iterator & _that) const - { - return iter == _that.iter; - } - Iterator(const typename DictionaryType::Iterator & _iter) - { - this->iter = _iter; - } - }; - Iterator begin() const - { - return Iterator(dict.begin()); - } - Iterator end() const - { - return Iterator(dict.end()); - } - public: - int Count() const - { - return dict.Count(); - } - void Clear() - { - dict.Clear(); - } - bool Add(const T& obj) - { - return dict.AddIfNotExists(obj, _DummyClass()); - } - bool Add(T && obj) - { - return dict.AddIfNotExists(_Move(obj), _DummyClass()); - } + template<typename T, typename DictionaryType> + class HashSetBase + { + protected: + DictionaryType dict; + private: + template<typename... Args> + void init(const T& v, Args... args) + { + add(v); + init(args...); + } + public: + HashSetBase() + {} + template<typename Arg, typename... Args> + HashSetBase(Arg arg, Args... args) + { + init(arg, args...); + } + HashSetBase(const HashSetBase& set) + { + operator=(set); + } + HashSetBase(HashSetBase&& set) + { + operator=(_Move(set)); + } + HashSetBase& operator=(const HashSetBase& set) + { + dict = set.dict; + return *this; + } + HashSetBase& operator=(HashSetBase&& set) + { + dict = _Move(set.dict); + return *this; + } + public: + class Iterator + { + private: + typename DictionaryType::Iterator iter; + public: + Iterator() = default; + T& operator*() const + { + return (*iter).key; + } + T* operator->() const + { + return &(*iter).key; + } + Iterator& operator++() + { + ++iter; + return *this; + } + Iterator operator++(int) + { + Iterator rs = *this; + operator++(); + return rs; + } + bool operator!=(const Iterator& that) const + { + return iter != that.iter; + } + bool operator==(const Iterator& that) const + { + return iter == that.iter; + } + Iterator(const typename DictionaryType::Iterator& _iter) + { + this->iter = _iter; + } + }; + Iterator begin() const + { + return Iterator(dict.begin()); + } + Iterator end() const + { + return Iterator(dict.end()); + } + public: + int getCount() const + { + return dict.getCount(); + } + void clear() + { + dict.clear(); + } bool add(const T& obj) { - return dict.AddIfNotExists(obj, _DummyClass()); + return dict.addIfNotExists(obj, _DummyClass()); } bool add(T&& obj) { - return dict.AddIfNotExists(_Move(obj), _DummyClass()); - } - void Remove(const T & obj) - { - dict.Remove(obj); - } - bool Contains(const T & obj) const - { - return dict.ContainsKey(obj); - } - }; - template <typename T> - class HashSet : public HashSetBase<T, Dictionary<T, _DummyClass>> - {}; + return dict.addIfNotExists(_Move(obj), _DummyClass()); + } + void remove(const T& obj) + { + dict.remove(obj); + } + bool contains(const T& obj) const + { + return dict.containsKey(obj); + } + }; + template <typename T> + class HashSet : public HashSetBase<T, Dictionary<T, _DummyClass>> + {}; template <typename TKey, typename TValue> class OrderedDictionary @@ -691,158 +683,158 @@ namespace Slang friend class ItemProxy; private: - inline int GetProbeOffset(int /*probeIdx*/) const + inline int getProbeOffset(int /*probeIdx*/) const { // quadratic probing return 1; } private: - int bucketSizeMinusOne; - int _count; - UIntSet marks; + int m_bucketCountMinusOne; + int m_count; + UIntSet m_marks; - LinkedList<KeyValuePair<TKey, TValue>> kvPairs; - LinkedNode<KeyValuePair<TKey, TValue>>** hashMap; - void Free() + LinkedList<KeyValuePair<TKey, TValue>> m_kvPairs; + LinkedNode<KeyValuePair<TKey, TValue>>** m_hashMap; + void deallocateAll() { - if (hashMap) - delete[] hashMap; - hashMap = 0; - kvPairs.Clear(); + if (m_hashMap) + delete[] m_hashMap; + m_hashMap = nullptr; + m_kvPairs.clear(); } - inline bool IsDeleted(int pos) const { return marks.contains((pos << 1) + 1); } - inline bool IsEmpty(int pos) const { return !marks.contains((pos << 1)); } - inline void SetDeleted(int pos, bool val) + inline bool isDeleted(int pos) const { return m_marks.contains((pos << 1) + 1); } + inline bool isEmpty(int pos) const { return !m_marks.contains((pos << 1)); } + inline void setDeleted(int pos, bool val) { if (val) - marks.add((pos << 1) + 1); + m_marks.add((pos << 1) + 1); else - marks.remove((pos << 1) + 1); + m_marks.remove((pos << 1) + 1); } - inline void SetEmpty(int pos, bool val) + inline void setEmpty(int pos, bool val) { if (val) - marks.remove((pos << 1)); + m_marks.remove((pos << 1)); else - marks.add((pos << 1)); + m_marks.add((pos << 1)); } struct FindPositionResult { - int ObjectPosition; - int InsertionPosition; + int objectPosition; + int insertionPosition; FindPositionResult() { - ObjectPosition = -1; - InsertionPosition = -1; + objectPosition = -1; + insertionPosition = -1; } FindPositionResult(int objPos, int insertPos) { - ObjectPosition = objPos; - InsertionPosition = insertPos; + objectPosition = objPos; + insertionPosition = insertPos; } }; - template <typename T> inline int GetHashPos(T& key) const + template <typename T> inline int getHashPos(T& key) const { const unsigned int hash = (unsigned int)getHashCode(key); - return ((unsigned int)(hash * 2654435761)) % bucketSizeMinusOne; + return ((unsigned int)(hash * 2654435761)) % m_bucketCountMinusOne; } - template <typename T> FindPositionResult FindPosition(const T& key) const + template <typename T> FindPositionResult findPosition(const T& key) const { - int hashPos = GetHashPos((T&)key); + int hashPos = getHashPos((T&)key); int insertPos = -1; int numProbes = 0; - while (numProbes <= bucketSizeMinusOne) + while (numProbes <= m_bucketCountMinusOne) { - if (IsEmpty(hashPos)) + if (isEmpty(hashPos)) { if (insertPos == -1) return FindPositionResult(-1, hashPos); else return FindPositionResult(-1, insertPos); } - else if (IsDeleted(hashPos)) + else if (isDeleted(hashPos)) { if (insertPos == -1) insertPos = hashPos; } - else if (hashMap[hashPos]->Value.Key == key) + else if (m_hashMap[hashPos]->value.key == key) { return FindPositionResult(hashPos, -1); } numProbes++; - hashPos = (hashPos + GetProbeOffset(numProbes)) & bucketSizeMinusOne; + hashPos = (hashPos + getProbeOffset(numProbes)) & m_bucketCountMinusOne; } if (insertPos != -1) return FindPositionResult(-1, insertPos); SLANG_ASSERT_FAILURE("Hash map is full. This indicates an error in Key::Equal or Key::GetHashCode."); } - TValue& _Insert(KeyValuePair<TKey, TValue>&& kvPair, int pos) + TValue& _insert(KeyValuePair<TKey, TValue>&& kvPair, int pos) { - auto node = kvPairs.AddLast(); - node->Value = _Move(kvPair); - hashMap[pos] = node; - SetEmpty(pos, false); - SetDeleted(pos, false); - return node->Value.Value; + auto node = m_kvPairs.addLast(); + node->value = _Move(kvPair); + m_hashMap[pos] = node; + setEmpty(pos, false); + setDeleted(pos, false); + return node->value.value; } - void Rehash() + void maybeRehash() { - if (bucketSizeMinusOne == -1 || _count / (float)bucketSizeMinusOne >= MaxLoadFactor) + if (m_bucketCountMinusOne == -1 || m_count / (float)m_bucketCountMinusOne >= kMaxLoadFactor) { - int newSize = (bucketSizeMinusOne + 1) * 2; + int newSize = (m_bucketCountMinusOne + 1) * 2; if (newSize == 0) { newSize = 16; } OrderedDictionary<TKey, TValue> newDict; - newDict.bucketSizeMinusOne = newSize - 1; - newDict.hashMap = new LinkedNode<KeyValuePair<TKey, TValue>>*[newSize]; - newDict.marks.resizeAndClear(newSize * 2); - if (hashMap) + newDict.m_bucketCountMinusOne = newSize - 1; + newDict.m_hashMap = new LinkedNode<KeyValuePair<TKey, TValue>>*[newSize]; + newDict.m_marks.resizeAndClear(newSize * 2); + if (m_hashMap) { for (auto& kvPair : *this) { - newDict.Add(_Move(kvPair)); + newDict.add(_Move(kvPair)); } } *this = _Move(newDict); } } - bool AddIfNotExists(KeyValuePair<TKey, TValue>&& kvPair) + bool addIfNotExists(KeyValuePair<TKey, TValue>&& kvPair) { - Rehash(); - auto pos = FindPosition(kvPair.Key); - if (pos.ObjectPosition != -1) + maybeRehash(); + auto pos = findPosition(kvPair.key); + if (pos.objectPosition != -1) return false; - else if (pos.InsertionPosition != -1) + else if (pos.insertionPosition != -1) { - _count++; - _Insert(_Move(kvPair), pos.InsertionPosition); + m_count++; + _insert(_Move(kvPair), pos.insertionPosition); return true; } else SLANG_ASSERT_FAILURE("Inconsistent find result returned. This is a bug in Dictionary implementation."); } - void Add(KeyValuePair<TKey, TValue>&& kvPair) + void add(KeyValuePair<TKey, TValue>&& kvPair) { - if (!AddIfNotExists(_Move(kvPair))) + if (!addIfNotExists(_Move(kvPair))) SLANG_ASSERT_FAILURE("The key already exists in Dictionary."); } - TValue& Set(KeyValuePair<TKey, TValue>&& kvPair) + TValue& set(KeyValuePair<TKey, TValue>&& kvPair) { - Rehash(); - auto pos = FindPosition(kvPair.Key); - if (pos.ObjectPosition != -1) + maybeRehash(); + auto pos = findPosition(kvPair.key); + if (pos.objectPosition != -1) { - hashMap[pos.ObjectPosition]->Delete(); - return _Insert(_Move(kvPair), pos.ObjectPosition); + m_hashMap[pos.objectPosition]->removeAndDelete(); + return _insert(_Move(kvPair), pos.objectPosition); } - else if (pos.InsertionPosition != -1) + else if (pos.insertionPosition != -1) { - _count++; - return _Insert(_Move(kvPair), pos.InsertionPosition); + m_count++; + return _insert(_Move(kvPair), pos.insertionPosition); } else SLANG_ASSERT_FAILURE("Inconsistent find result returned. This is a bug in Dictionary implementation."); @@ -853,76 +845,76 @@ namespace Slang typename LinkedList<KeyValuePair<TKey, TValue>>::Iterator begin() const { - return kvPairs.begin(); + return m_kvPairs.begin(); } typename LinkedList<KeyValuePair<TKey, TValue>>::Iterator end() const { - return kvPairs.end(); + return m_kvPairs.end(); } public: - void Add(const TKey& key, const TValue& value) + void add(const TKey& key, const TValue& value) { - Add(KeyValuePair<TKey, TValue>(key, value)); + add(KeyValuePair<TKey, TValue>(key, value)); } - void Add(TKey&& key, TValue&& value) + void add(TKey&& key, TValue&& value) { - Add(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); + add(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); } - bool AddIfNotExists(const TKey& key, const TValue& value) + bool addIfNotExists(const TKey& key, const TValue& value) { - return AddIfNotExists(KeyValuePair<TKey, TValue>(key, value)); + return addIfNotExists(KeyValuePair<TKey, TValue>(key, value)); } - bool AddIfNotExists(TKey&& key, TValue&& value) + bool addIfNotExists(TKey&& key, TValue&& value) { - return AddIfNotExists(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); + return addIfNotExists(KeyValuePair<TKey, TValue>(_Move(key), _Move(value))); } - void Remove(const TKey& key) + void remove(const TKey& key) { - if (_count > 0) + if (m_count > 0) { - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) + auto pos = findPosition(key); + if (pos.objectPosition != -1) { - kvPairs.Delete(hashMap[pos.ObjectPosition]); - hashMap[pos.ObjectPosition] = 0; - SetDeleted(pos.ObjectPosition, true); - _count--; + m_kvPairs.removeAndDelete(m_hashMap[pos.objectPosition]); + m_hashMap[pos.objectPosition] = 0; + setDeleted(pos.objectPosition, true); + m_count--; } } } - void Clear() + void clear() { - _count = 0; - kvPairs.Clear(); - marks.clear(); + m_count = 0; + m_kvPairs.clear(); + m_marks.clear(); } - template <typename T> bool ContainsKey(const T& key) const + template <typename T> bool containsKey(const T& key) const { - if (bucketSizeMinusOne == -1) + if (m_bucketCountMinusOne == -1) return false; - auto pos = FindPosition(key); - return pos.ObjectPosition != -1; + auto pos = findPosition(key); + return pos.objectPosition != -1; } - template <typename T> TValue* TryGetValue(const T& key) const + template <typename T> TValue* tryGetValue(const T& key) const { - if (bucketSizeMinusOne == -1) + if (m_bucketCountMinusOne == -1) return nullptr; - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) + auto pos = findPosition(key); + if (pos.objectPosition != -1) { - return &(hashMap[pos.ObjectPosition]->Value.Value); + return &(m_hashMap[pos.objectPosition]->value.value); } return nullptr; } - template <typename T> bool TryGetValue(const T& key, TValue& value) const + template <typename T> bool tryGetValue(const T& key, TValue& value) const { - if (bucketSizeMinusOne == -1) + if (m_bucketCountMinusOne == -1) return false; - auto pos = FindPosition(key); - if (pos.ObjectPosition != -1) + auto pos = findPosition(key); + if (pos.objectPosition != -1) { - value = hashMap[pos.ObjectPosition]->Value.Value; + value = m_hashMap[pos.objectPosition]->value.value; return true; } return false; @@ -944,67 +936,68 @@ namespace Slang this->dict = _dict; this->key = _Move(_key); } - TValue& GetValue() const + TValue& getValue() const { - auto pos = dict->FindPosition(key); - if (pos.ObjectPosition != -1) + auto pos = dict->findPosition(key); + if (pos.objectPosition != -1) { - return dict->hashMap[pos.ObjectPosition]->Value.Value; + return dict->m_hashMap[pos.objectPosition]->value.value; } else { SLANG_ASSERT_FAILURE("The key does not exists in dictionary."); } } - inline TValue& operator()() const { return GetValue(); } - operator TValue&() const { return GetValue(); } + inline TValue& operator()() const { return getValue(); } + operator TValue&() const { return getValue(); } TValue& operator=(const TValue& val) { return ((OrderedDictionary<TKey, TValue>*)dict) - ->Set(KeyValuePair<TKey, TValue>(_Move(key), val)); + ->set(KeyValuePair<TKey, TValue>(_Move(key), val)); } TValue& operator=(TValue&& val) { return ((OrderedDictionary<TKey, TValue>*)dict) - ->Set(KeyValuePair<TKey, TValue>(_Move(key), _Move(val))); + ->set(KeyValuePair<TKey, TValue>(_Move(key), _Move(val))); } }; ItemProxy operator[](const TKey& key) const { return ItemProxy(key, this); } ItemProxy operator[](TKey&& key) const { return ItemProxy(_Move(key), this); } - int Count() const { return _count; } - KeyValuePair<TKey, TValue>& First() const { return kvPairs.First(); } - KeyValuePair<TKey, TValue>& Last() const { return kvPairs.Last(); } + + int getCount() const { return m_count; } + KeyValuePair<TKey, TValue>& getFirst() const { return m_kvPairs.getFirst(); } + KeyValuePair<TKey, TValue>& getLast() const { return m_kvPairs.getLast(); } private: template <typename... Args> - void Init(const KeyValuePair<TKey, TValue>& kvPair, Args... args) + void init(const KeyValuePair<TKey, TValue>& kvPair, Args... args) { - Add(kvPair); - Init(args...); + add(kvPair); + init(args...); } public: OrderedDictionary() { - bucketSizeMinusOne = -1; - _count = 0; - hashMap = 0; + m_bucketCountMinusOne = -1; + m_count = 0; + m_hashMap = 0; } template <typename Arg, typename... Args> OrderedDictionary(Arg arg, Args... args) { - Init(arg, args...); + init(arg, args...); } OrderedDictionary(const OrderedDictionary<TKey, TValue>& other) - : bucketSizeMinusOne(-1) - , _count(0) - , hashMap(0) + : m_bucketCountMinusOne(-1) + , m_count(0) + , m_hashMap(0) { *this = other; } OrderedDictionary(OrderedDictionary<TKey, TValue>&& other) - : bucketSizeMinusOne(-1) - , _count(0) - , hashMap(0) + : m_bucketCountMinusOne(-1) + , m_count(0) + , m_hashMap(0) { *this = (_Move(other)); } @@ -1013,9 +1006,9 @@ namespace Slang { if (this == &other) return *this; - Clear(); + clear(); for (auto& item : other) - Add(item.Key, item.Value); + add(item.key, item.value); return *this; } OrderedDictionary<TKey, TValue>& @@ -1023,18 +1016,18 @@ namespace Slang { if (this == &other) return *this; - Free(); - bucketSizeMinusOne = other.bucketSizeMinusOne; - _count = other._count; - hashMap = other.hashMap; - marks = _Move(other.marks); - other.hashMap = 0; - other._count = 0; - other.bucketSizeMinusOne = -1; - kvPairs = _Move(other.kvPairs); + deallocateAll(); + m_bucketCountMinusOne = other.m_bucketCountMinusOne; + m_count = other.m_count; + m_hashMap = other.m_hashMap; + m_marks = _Move(other.m_marks); + other.m_hashMap = 0; + other.m_count = 0; + other.m_bucketCountMinusOne = -1; + m_kvPairs = _Move(other.m_kvPairs); return *this; } - ~OrderedDictionary() { Free(); } + ~OrderedDictionary() { deallocateAll(); } }; template <typename T> class OrderedHashSet : public HashSetBase<T, OrderedDictionary<T, _DummyClass>> @@ -1042,11 +1035,11 @@ namespace Slang public: T& getLast() { - return this->dict.Last().Key; + return this->dict.getLast().key; } void removeLast() { - this->Remove(getLast()); + this->remove(getLast()); } }; } diff --git a/source/core/slang-file-system.cpp b/source/core/slang-file-system.cpp index db75e5365..e6d84cac1 100644 --- a/source/core/slang-file-system.cpp +++ b/source/core/slang-file-system.cpp @@ -199,7 +199,7 @@ SlangResult OSFileSystem::enumeratePathContents(const char* path, FileSystemCont { void accept(Path::Type type, const UnownedStringSlice& filename) SLANG_OVERRIDE { - m_buffer.Clear(); + m_buffer.clear(); m_buffer.append(filename); SlangPathType pathType; @@ -321,7 +321,7 @@ CacheFileSystem::~CacheFileSystem() { for (const auto& pair : m_uniqueIdentityMap) { - PathInfo* pathInfo = pair.Value; + PathInfo* pathInfo = pair.value; delete pathInfo; } } @@ -376,12 +376,12 @@ void CacheFileSystem::clearCache() { for (const auto& pair : m_uniqueIdentityMap) { - PathInfo* pathInfo = pair.Value; + PathInfo* pathInfo = pair.value; delete pathInfo; } - m_uniqueIdentityMap.Clear(); - m_pathMap.Clear(); + m_uniqueIdentityMap.clear(); + m_pathMap.clear(); if (m_fileSystemExt) { @@ -438,7 +438,7 @@ SlangResult CacheFileSystem::enumeratePathContents(const char* path, FileSystemC { // NOTE! The currentPath can be a *non* simplified path (the m_pathMap is the cache of paths simplified and other to a file/directory) // Also note that there will always be the simplified version of the path in cache. - const String& currentPath = pair.Key; + const String& currentPath = pair.key; // If it doesn't start with simplified path, then it can't be a hit if (!currentPath.startsWith(simplifiedPath)) @@ -468,7 +468,7 @@ SlangResult CacheFileSystem::enumeratePathContents(const char* path, FileSystemC // Let's check that fact... SLANG_ASSERT(foundPath[remaining.getLength()] == 0); - PathInfo* pathInfo = pair.Value; + PathInfo* pathInfo = pair.value; SlangPathType pathType; if (SLANG_FAILED(_getPathType(pathInfo, currentPath.getBuffer(), &pathType))) @@ -581,11 +581,11 @@ CacheFileSystem::PathInfo* CacheFileSystem::_resolveUniqueIdentityCacheInfo(cons // Now try looking up by uniqueIdentity path. If not found, add a new result PathInfo* pathInfo = nullptr; - if (!m_uniqueIdentityMap.TryGetValue(uniqueIdentity, pathInfo)) + if (!m_uniqueIdentityMap.tryGetValue(uniqueIdentity, pathInfo)) { // Create with found uniqueIdentity pathInfo = new PathInfo(uniqueIdentity); - m_uniqueIdentityMap.Add(uniqueIdentity, pathInfo); + m_uniqueIdentityMap.add(uniqueIdentity, pathInfo); } // At this point they must have same uniqueIdentity @@ -623,7 +623,7 @@ CacheFileSystem::PathInfo* CacheFileSystem::_resolvePathCacheInfo(const String& { // Lookup in path cache PathInfo* pathInfo; - if (m_pathMap.TryGetValue(path, pathInfo)) + if (m_pathMap.tryGetValue(path, pathInfo)) { // Found so done return pathInfo; @@ -632,7 +632,7 @@ CacheFileSystem::PathInfo* CacheFileSystem::_resolvePathCacheInfo(const String& // Try getting or creating taking into account possible path simplification pathInfo = _resolveSimplifiedPathCacheInfo(path); // Always add the result to the path cache (even if null) - m_pathMap.Add(path, pathInfo); + m_pathMap.add(path, pathInfo); return pathInfo; } diff --git a/source/core/slang-implicit-directory-collector.cpp b/source/core/slang-implicit-directory-collector.cpp index 994ebd4d7..169deeb30 100644 --- a/source/core/slang-implicit-directory-collector.cpp +++ b/source/core/slang-implicit-directory-collector.cpp @@ -77,8 +77,8 @@ SlangResult ImplicitDirectoryCollector::enumerate(FileSystemContentsCallBack cal { const auto& pair = m_map.getAt(i); - UnownedStringSlice path = pair.Key; - SlangPathType pathType = SlangPathType(pair.Value); + UnownedStringSlice path = pair.key; + SlangPathType pathType = SlangPathType(pair.value); // Note *is* 0 terminated in the pool // Let's check tho diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 30ba41d0f..50e98c60c 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -324,7 +324,7 @@ namespace Slang /* static */void Path::combineIntoBuilder(const UnownedStringSlice& path1, const UnownedStringSlice& path2, StringBuilder& outBuilder) { - outBuilder.Clear(); + outBuilder.clear(); outBuilder.Append(path1); append(outBuilder, path2); } @@ -519,7 +519,7 @@ namespace Slang /* static */void Path::join(const UnownedStringSlice* slices, Index count, StringBuilder& out) { - out.Clear(); + out.clear(); if (count == 0) { diff --git a/source/core/slang-linked-list.h b/source/core/slang-linked-list.h index 38da2ccce..41709c9d0 100644 --- a/source/core/slang-linked-list.h +++ b/source/core/slang-linked-list.h @@ -21,17 +21,17 @@ private: LinkedList<T>* list; public: - T Value; + T value; LinkedNode(LinkedList<T>* lnk) : list(lnk) { }; - LinkedNode<T>* GetPrevious() { return prev; }; - LinkedNode<T>* GetNext() { return next; }; - LinkedNode<T>* InsertAfter(const T& nData) + LinkedNode<T>* getPrevious() { return prev; }; + LinkedNode<T>* getNext() { return next; }; + LinkedNode<T>* insertAfter(const T& nData) { LinkedNode<T>* n = new LinkedNode<T>(list); - n->Value = nData; + n->value = nData; n->prev = this; n->next = this->next; LinkedNode<T>* npp = n->next; @@ -45,10 +45,10 @@ public: list->count++; return n; }; - LinkedNode<T>* InsertBefore(const T& nData) + LinkedNode<T>* insertBefore(const T& nData) { LinkedNode<T>* n = new LinkedNode<T>(list); - n->Value = nData; + n->value = nData; n->prev = prev; n->next = this; prev = n; @@ -60,7 +60,7 @@ public: list->count++; return n; }; - void Delete() + void removeAndDelete() { if (prev) prev->next = next; @@ -84,38 +84,38 @@ template <typename T> class LinkedList template <typename T1> friend class LinkedNode; private: - LinkedNode<T>*head, *tail; + LinkedNode<T>* head, *tail; int count; public: class Iterator { public: - LinkedNode<T>*Current, *Next; - void SetCurrent(LinkedNode<T>* cur) + LinkedNode<T>* current, *next; + void setCurrent(LinkedNode<T>* cur) { - Current = cur; - if (Current) - Next = Current->GetNext(); + current = cur; + if (current) + next = current->getNext(); else - Next = 0; + next = 0; } - Iterator() { Current = Next = 0; } - Iterator(LinkedNode<T>* cur) { SetCurrent(cur); } - T& operator*() const { return Current->Value; } + Iterator() { current = next = nullptr; } + Iterator(LinkedNode<T>* cur) { setCurrent(cur); } + T& operator*() const { return current->value; } Iterator& operator++() { - SetCurrent(Next); + setCurrent(next); return *this; } Iterator operator++(int) { Iterator rs = *this; - SetCurrent(Next); + setCurrent(next); return rs; } - bool operator!=(const Iterator& iter) const { return Current != iter.Current; } - bool operator==(const Iterator& iter) const { return Current == iter.Current; } + bool operator!=(const Iterator& iter) const { return current != iter.current; } + bool operator==(const Iterator& iter) const { return current == iter.current; } }; Iterator begin() const { return Iterator(head); } Iterator end() const { return Iterator(0); } @@ -126,7 +126,7 @@ public: , tail(0) , count(0) {} - ~LinkedList() { Clear(); } + ~LinkedList() { clear(); } LinkedList(const LinkedList<T>& link) : head(0) , tail(0) @@ -144,39 +144,39 @@ public: LinkedList<T>& operator=(LinkedList<T>&& link) { if (head != 0) - Clear(); + clear(); head = link.head; tail = link.tail; count = link.count; link.head = 0; link.tail = 0; link.count = 0; - for (auto node = head; node; node = node->GetNext()) + for (auto node = head; node; node = node->getNext()) node->list = this; return *this; } LinkedList<T>& operator=(const LinkedList<T>& link) { - if (head != 0) - Clear(); + if (head != nullptr) + clear(); auto p = link.head; while (p) { - AddLast(p->Value); - p = p->GetNext(); + addLast(p->value); + p = p->getNext(); } return *this; } - template <typename IteratorFunc> void ForEach(const IteratorFunc& f) + template <typename IteratorFunc> void forEach(const IteratorFunc& f) { auto p = head; while (p) { - f(p->Value); - p = p->GetNext(); + f(p->value); + p = p->getNext(); } } - LinkedNode<T>* GetNode(int x) + LinkedNode<T>* getNode(int x) { LinkedNode<T>* pCur = head; for (int i = 0; i < x; i++) @@ -188,33 +188,33 @@ public: } return pCur; }; - LinkedNode<T>* Find(const T& fData) + LinkedNode<T>* find(const T& fData) { for (LinkedNode<T>* pCur = head; pCur; pCur = pCur->next) { - if (pCur->Value == fData) + if (pCur->value == fData) return pCur; } - return 0; + return nullptr; }; - LinkedNode<T>* FirstNode() const { return head; }; - T& First() const + LinkedNode<T>* getFirstNode() const { return head; }; + T& getFirst() const { if (!head) SLANG_UNEXPECTED("LinkedList: index out of range."); - return head->Value; + return head->value; } - T& Last() const + T& getLast() const { if (!tail) SLANG_UNEXPECTED("LinkedList: index out of range."); - return tail->Value; + return tail->value; } - LinkedNode<T>* LastNode() const { return tail; }; - LinkedNode<T>* AddLast(const T& nData) + LinkedNode<T>* getLastNode() const { return tail; }; + LinkedNode<T>* addLast(const T& nData) { LinkedNode<T>* n = new LinkedNode<T>(this); - n->Value = nData; + n->value = nData; n->prev = tail; if (tail) tail->next = n; @@ -226,7 +226,7 @@ public: return n; }; // Insert a blank node - LinkedNode<T>* AddLast() + LinkedNode<T>* addLast() { LinkedNode<T>* n = new LinkedNode<T>(this); n->prev = tail; @@ -239,15 +239,15 @@ public: count++; return n; }; - LinkedNode<T>* AddFirst(const T& nData) + LinkedNode<T>* addFirst(const T& nData) { LinkedNode<T>* n = new LinkedNode<T>(this); - n->Value = nData; - AddFirst(n); + n->value = nData; + addFirst(n); count++; return n; }; - void AddFirst(LinkedNode<T>* n) + void addFirst(LinkedNode<T>* n) { n->prev = 0; n->next = head; @@ -257,7 +257,7 @@ public: if (!tail) tail = n; } - void RemoveFromList(LinkedNode<T>* n) + void removeFromList(LinkedNode<T>* n) { LinkedNode<T>*n1, *n2 = 0; n1 = n->prev; @@ -273,7 +273,7 @@ public: n->prev = nullptr; n->next = nullptr; } - void Delete(LinkedNode<T>* n, int Count = 1) + void removeAndDelete(LinkedNode<T>* n, int Count = 1) { LinkedNode<T>*cur, *next; cur = n; @@ -281,7 +281,7 @@ public: for (int i = 0; i < Count; i++) { next = cur->next; - RemoveFromList(cur); + removeFromList(cur); delete cur; cur = next; numDeleted++; @@ -290,7 +290,7 @@ public: } count -= numDeleted; } - void Clear() + void clear() { for (LinkedNode<T>* n = head; n;) { @@ -302,17 +302,17 @@ public: tail = 0; count = 0; } - List<T> ToList() const + List<T> toList() const { List<T> rs; rs.Reserve(count); for (auto& item : *this) { - rs.Add(item); + rs.add(item); } return rs; } - int Count() { return count; } + int getCount() { return count; } }; } // namespace Slang #endif diff --git a/source/core/slang-memory-file-system.cpp b/source/core/slang-memory-file-system.cpp index a6bc05f24..eabd13072 100644 --- a/source/core/slang-memory-file-system.cpp +++ b/source/core/slang-memory-file-system.cpp @@ -55,7 +55,7 @@ MemoryFileSystem::Entry* MemoryFileSystem::_getEntryFromCanonicalPath(const Stri } else { - return m_entries.TryGetValue(canonicalPath); + return m_entries.tryGetValue(canonicalPath); } } @@ -173,7 +173,7 @@ SlangResult MemoryFileSystem::enumeratePathContents(const char* path, FileSystem // If it is a directory, we need to see if there is anything in it for (const auto& pair : m_entries) { - const Entry* childEntry = &pair.Value; + const Entry* childEntry = &pair.value; collector.addPath(childEntry->m_type, childEntry->m_canonicalPath.getUnownedSlice()); } @@ -250,7 +250,7 @@ SlangResult MemoryFileSystem::_requireFile(const char* path, Entry** outEntry) { Entry entry; entry.initFile(canonicalPath); - m_entries.Add(canonicalPath, entry); + m_entries.add(canonicalPath, entry); foundEntry = _getEntryFromCanonicalPath(canonicalPath); } @@ -277,7 +277,7 @@ SlangResult MemoryFileSystem::remove(const char* path) // If it is a directory, we need to see if there is anything in it for (const auto& pair : m_entries) { - const Entry* childEntry = &pair.Value; + const Entry* childEntry = &pair.value; collector.addPath(childEntry->m_type, childEntry->m_canonicalPath.getUnownedSlice()); if (collector.hasContent()) { @@ -289,7 +289,7 @@ SlangResult MemoryFileSystem::remove(const char* path) // Reset so doesn't hold references/keep memory in scope entry->reset(); - m_entries.Remove(canonicalPath); + m_entries.remove(canonicalPath); return SLANG_OK; } @@ -308,7 +308,7 @@ SlangResult MemoryFileSystem::createDirectory(const char* path) Entry entry; entry.initDirectory(canonicalPath); - m_entries.Add(canonicalPath, entry); + m_entries.add(canonicalPath, entry); return SLANG_OK; } diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp index 9185559a2..f28a25f7f 100644 --- a/source/core/slang-platform.cpp +++ b/source/core/slang-platform.cpp @@ -69,7 +69,7 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY); String pathString = String::fromWString(path); // We don't want the instance name, just the path to it - out.Clear(); + out.clear(); out.append(Path::getParentDirectory(pathString)); return out.getLength() > 0 ? SLANG_OK : SLANG_FAIL; diff --git a/source/core/slang-riff-file-system.cpp b/source/core/slang-riff-file-system.cpp index 6fe8b0952..9db330956 100644 --- a/source/core/slang-riff-file-system.cpp +++ b/source/core/slang-riff-file-system.cpp @@ -213,7 +213,7 @@ SlangResult RiffFileSystem::loadArchive(const void* archive, size_t archiveSizeI } // Add to the list of entries - m_entries.Add(dstEntry.m_canonicalPath, dstEntry); + m_entries.add(dstEntry.m_canonicalPath, dstEntry); } } @@ -237,7 +237,7 @@ SlangResult RiffFileSystem::storeArchive(bool blobOwnsContent, ISlangBlob** outB for (const auto& pair : m_entries) { - const Entry* srcEntry = &pair.Value; + const Entry* srcEntry = &pair.value; // Ignore the root entry if (srcEntry->m_canonicalPath == toSlice(".")) diff --git a/source/core/slang-rtti-info.cpp b/source/core/slang-rtti-info.cpp index c35444d03..9e0a3796a 100644 --- a/source/core/slang-rtti-info.cpp +++ b/source/core/slang-rtti-info.cpp @@ -197,7 +197,7 @@ StructRttiInfo StructRttiBuilder::make() RttiTypeFuncs RttiTypeFuncsMap::getFuncsForType(const RttiInfo* rttiInfo) { - if (auto funcsPtr = m_map.TryGetValue(rttiInfo)) + if (auto funcsPtr = m_map.tryGetValue(rttiInfo)) { return *funcsPtr; } @@ -207,13 +207,13 @@ RttiTypeFuncs RttiTypeFuncsMap::getFuncsForType(const RttiInfo* rttiInfo) const auto funcs = RttiUtil::getDefaultTypeFuncs(rttiInfo); // Add to the map - m_map.Add(rttiInfo, funcs); + m_map.add(rttiInfo, funcs); return funcs; } void RttiTypeFuncsMap::add(const RttiInfo* rttiInfo, const RttiTypeFuncs& funcs) { - if (auto funcsPtr = m_map.TryGetValueOrAdd(rttiInfo, funcs)) + if (auto funcsPtr = m_map.tryGetValueOrAdd(rttiInfo, funcs)) { // If there are funcs set, they aren't valid otherwise this would be // replacing, so assert on that scenario. diff --git a/source/core/slang-rtti-util.cpp b/source/core/slang-rtti-util.cpp index 9d02ec23b..65ddf8554 100644 --- a/source/core/slang-rtti-util.cpp +++ b/source/core/slang-rtti-util.cpp @@ -23,6 +23,7 @@ struct ListFuncs new (dst + i) Type; } } + static void copyArray(RttiTypeFuncsMap* typeMap, const RttiInfo* rttiInfo, void* inDst, const void* inSrc, Index count) { SLANG_ASSERT(rttiInfo->m_kind == RttiInfo::Kind::List); @@ -455,7 +456,7 @@ static bool _isStructDefault(const StructRttiInfo* type, const void* src) case RttiInfo::Kind::Dictionary: { const auto& v = *(const Dictionary<Byte, Byte>*)src; - return v.Count() == 0; + return v.getCount() == 0; } case RttiInfo::Kind::Other: { diff --git a/source/core/slang-string-slice-index-map.h b/source/core/slang-string-slice-index-map.h index 5aef62253..c57e0f570 100644 --- a/source/core/slang-string-slice-index-map.h +++ b/source/core/slang-string-slice-index-map.h @@ -68,8 +68,8 @@ Index StringSliceIndexMap::getValue(const UnownedStringSlice& key) KeyValuePair<UnownedStringSlice, Index> StringSliceIndexMap::getAt(CountIndex countIndex) const { KeyValuePair<UnownedStringSlice, Index> pair; - pair.Key = m_pool.getSlice(StringSlicePool::Handle(countIndex)); - pair.Value = m_indexMap[countIndex]; + pair.key = m_pool.getSlice(StringSlicePool::Handle(countIndex)); + pair.value = m_indexMap[countIndex]; return pair; } diff --git a/source/core/slang-string-slice-pool.cpp b/source/core/slang-string-slice-pool.cpp index 5c4c7f61f..692bc2b9a 100644 --- a/source/core/slang-string-slice-pool.cpp +++ b/source/core/slang-string-slice-pool.cpp @@ -70,7 +70,7 @@ void StringSlicePool::_set(const ThisType& rhs) m_slices[i] = dstSlice; // Add to the map - m_map.Add(dstSlice, Handle(i)); + m_map.add(dstSlice, Handle(i)); // Skip to next slices storage dst += sliceSize + 1; @@ -109,7 +109,7 @@ bool StringSlicePool::operator==(const ThisType& rhs) const void StringSlicePool::clear() { - m_map.Clear(); + m_map.clear(); m_arena.deallocateAll(); switch (m_style) @@ -123,7 +123,7 @@ void StringSlicePool::clear() m_slices[1] = UnownedStringSlice::fromLiteral(""); // Add the empty entry - m_map.Add(m_slices[1], kEmptyHandle); + m_map.add(m_slices[1], kEmptyHandle); break; } case Style::Empty: @@ -145,7 +145,7 @@ void StringSlicePool::swapWith(ThisType& rhs) StringSlicePool::Handle StringSlicePool::add(const Slice& slice) { - const Handle* handlePtr = m_map.TryGetValue(slice); + const Handle* handlePtr = m_map.tryGetValue(slice); if (handlePtr) { return *handlePtr; @@ -157,13 +157,13 @@ StringSlicePool::Handle StringSlicePool::add(const Slice& slice) const auto index = m_slices.getCount(); m_slices.add(scopePath); - m_map.Add(scopePath, Handle(index)); + m_map.add(scopePath, Handle(index)); return Handle(index); } bool StringSlicePool::findOrAdd(const Slice& slice, Handle& outHandle) { - const Handle* handlePtr = m_map.TryGetValue(slice); + const Handle* handlePtr = m_map.tryGetValue(slice); if (handlePtr) { outHandle = *handlePtr; @@ -177,7 +177,7 @@ bool StringSlicePool::findOrAdd(const Slice& slice, Handle& outHandle) // Add using the arenas copy Handle newHandle = Handle(m_slices.getCount()); - m_map.Add(scopeSlice, newHandle); + m_map.add(scopeSlice, newHandle); // Add to slices list m_slices.add(scopeSlice); @@ -226,7 +226,7 @@ StringSlicePool::Handle StringSlicePool::add(const char* chars) Index StringSlicePool::findIndex(const Slice& slice) const { - const Handle* handlePtr = m_map.TryGetValue(slice); + const Handle* handlePtr = m_map.tryGetValue(slice); return handlePtr ? Index(*handlePtr) : -1; } diff --git a/source/core/slang-string.h b/source/core/slang-string.h index ecdba46be..533d30827 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -1059,7 +1059,7 @@ namespace Slang #endif friend std::ostream& operator<< (std::ostream& stream, const String& s); - void Clear() + void clear() { m_buffer.setNull(); } diff --git a/source/core/slang-token-reader.cpp b/source/core/slang-token-reader.cpp index 5acc1736c..be2461796 100644 --- a/source/core/slang-token-reader.cpp +++ b/source/core/slang-token-reader.cpp @@ -338,7 +338,7 @@ namespace Misc { derivative = LexDerivative::None; tokenList.add(Token(type, tokenBuilder.ToString(), tokenLine, tokenCol, int(pos), file, tokenFlags)); tokenFlags = 0; - tokenBuilder.Clear(); + tokenBuilder.clear(); }; auto ProcessTransferChar = [&](char nextChar) { @@ -462,17 +462,17 @@ namespace Misc { { line = 0; col = 0; - tokenBuilder.Clear(); + tokenBuilder.clear(); } else if (tokenStr == "#line") { derivative = LexDerivative::Line; - tokenBuilder.Clear(); + tokenBuilder.clear(); } else if (tokenStr == "#file") { derivative = LexDerivative::File; - tokenBuilder.Clear(); + tokenBuilder.clear(); line = 0; col = 0; } @@ -492,7 +492,7 @@ namespace Misc { { //do token analyze ParseOperators(tokenBuilder.ToString(), tokenList, tokenFlags, tokenLine, tokenCol, (int)(pos - tokenBuilder.getLength()), file); - tokenBuilder.Clear(); + tokenBuilder.clear(); state = State::Start; } break; @@ -539,7 +539,7 @@ namespace Misc { derivative = LexDerivative::None; line = StringToInt(tokenBuilder.ToString()) - 1; col = 0; - tokenBuilder.Clear(); + tokenBuilder.clear(); } else { @@ -616,7 +616,7 @@ namespace Misc { { derivative = LexDerivative::None; file = tokenBuilder.ToString(); - tokenBuilder.Clear(); + tokenBuilder.clear(); } else { diff --git a/source/core/slang-token-reader.h b/source/core/slang-token-reader.h index 26539732c..4f0f9791a 100644 --- a/source/core/slang-token-reader.h +++ b/source/core/slang-token-reader.h @@ -284,7 +284,7 @@ namespace Misc { auto str = sb.ToString(); if (str.getLength() != 0) result.add(str); - sb.Clear(); + sb.clear(); } else sb << text[i]; |
