diff --git a/src/common/classes/array.h b/src/common/classes/array.h index f99211e27c..08e1ef7270 100644 --- a/src/common/classes/array.h +++ b/src/common/classes/array.h @@ -33,7 +33,7 @@ namespace Firebird { // Static part of the array -template +template class InlineStorage : public AutoStorage { public: explicit InlineStorage(MemoryPool& p) : AutoStorage(p) { } @@ -42,7 +42,7 @@ protected: T* getStorage() { return buffer; } - int getStorageSize() const { + size_t getStorageSize() const { return Capacity; } private: @@ -57,7 +57,7 @@ public: EmptyStorage() : AutoStorage() { } protected: T* getStorage() { return NULL; } - int getStorageSize() const { return 0; } + size_t getStorageSize() const { return 0; } }; // Dynamic array of simple types @@ -66,14 +66,14 @@ class Array : protected Storage { public: explicit Array(MemoryPool& p) : Storage(p), count(0), capacity(this->getStorageSize()), data(this->getStorage()) { } - Array(MemoryPool& p, int InitialCapacity) : + Array(MemoryPool& p, size_t InitialCapacity) : Storage(p), count(0), capacity(this->getStorageSize()), data(this->getStorage()) { ensureCapacity(InitialCapacity); } Array() : count(0), capacity(this->getStorageSize()), data(this->getStorage()) { } - explicit Array(int InitialCapacity) : count(0), + explicit Array(size_t InitialCapacity) : count(0), capacity(this->getStorageSize()), data(this->getStorage()) { ensureCapacity(InitialCapacity); @@ -84,11 +84,11 @@ public: } void clear() { count = 0; }; protected: - const T& getElement(int index) const { + const T& getElement(size_t index) const { fb_assert(index >= 0 && index < count); return data[index]; } - T& getElement(int index) { + T& getElement(size_t index) { fb_assert(index >= 0 && index < count); return data[index]; } @@ -105,10 +105,10 @@ public: count = L.count; return *this; } - const T& operator[](int index) const { + const T& operator[](size_t index) const { return getElement(index); } - T& operator[](int index) { + T& operator[](size_t index) { return getElement(index); } const T& front() const { @@ -131,39 +131,39 @@ public: } T* begin() { return data; } T* end() { return data + count; } - void insert(int index, const T& item) { + void insert(size_t index, const T& item) { fb_assert(index >= 0 && index <= count); ensureCapacity(count + 1); memmove(data + index + 1, data + index, sizeof(T) * (count++ - index)); data[index] = item; } - void insert(int index, const Array& L) { + void insert(size_t index, const Array& L) { fb_assert(index >= 0 && index <= count); ensureCapacity(count + L.count); memmove(data + index + L.count, data + index, sizeof(T) * (count - index)); memcpy(data + index, L.data, L.count); count += L.count; } - int add(const T& item) { + size_t add(const T& item) { ensureCapacity(count + 1); data[count++] = item; return count; }; - void remove(int index) { + void remove(size_t index) { fb_assert(index >= 0 && index < count); memmove(data + index, data + index + 1, sizeof(T) * (--count - index)); } void remove(T* itr) { - int index = itr - begin(); + size_t index = itr - begin(); fb_assert(index >= 0 && index < count); memmove(data + index, data + index + 1, sizeof(T) * (--count - index)); } - void shrink(int newCount) { + void shrink(size_t newCount) { fb_assert(newCount <= count); count = newCount; }; // Grow size of our array and zero-initialize new items - void grow(int newCount) { + void grow(size_t newCount) { fb_assert(newCount >= count); ensureCapacity(newCount); memset(data + count, 0, sizeof(T) * (newCount - count)); @@ -174,8 +174,8 @@ public: memcpy(data + count, L.data, sizeof(T) * L.count); count += L.count; } - int getCount() const { return count; } - int getCapacity() const { return capacity; } + size_t getCount() const { return count; } + size_t getCapacity() const { return capacity; } void push(const T& item) { add(item); } @@ -185,7 +185,7 @@ public: return data[count]; } // prepare array to be used as a buffer of capacity items - T* getBuffer(int capacityL) { + T* getBuffer(size_t capacityL) { ensureCapacity(capacityL); count = capacityL; return data; @@ -200,9 +200,9 @@ public: } protected: - int count, capacity; + size_t count, capacity; T* data; - void ensureCapacity(int newcapacity) { + void ensureCapacity(size_t newcapacity) { if (newcapacity > capacity) { if (newcapacity < capacity * 2) { newcapacity = capacity * 2; @@ -229,14 +229,14 @@ template > class SortedArray : public Array { public: - SortedArray(MemoryPool& p, int s) : Array(p, s) {} + SortedArray(MemoryPool& p, size_t s) : Array(p, s) {} explicit SortedArray(MemoryPool& p) : Array(p) {} - explicit SortedArray(int s) : Array(s) {} + explicit SortedArray(size_t s) : Array(s) {} SortedArray() : Array() {} - bool find(const Key& item, int& pos) const { - int highBound = this->count, lowBound = 0; + bool find(const Key& item, size_t& pos) const { + size_t highBound = this->count, lowBound = 0; while (highBound > lowBound) { - int temp = (highBound + lowBound) >> 1; + size_t temp = (highBound + lowBound) >> 1; if (Cmp::greaterThan(item, KeyOfValue::generate(this, this->data[temp]))) lowBound = temp + 1; else @@ -246,8 +246,8 @@ public: return highBound != this->count && !Cmp::greaterThan(KeyOfValue::generate(this, this->data[lowBound]), item); } - int add(const Value& item) { - int pos; + size_t add(const Value& item) { + size_t pos; find(KeyOfValue::generate(this, item), pos); insert(pos, item); return pos; @@ -255,14 +255,14 @@ public: }; // Nice shorthand for arrays with static part -template +template class HalfStaticArray : public Array > { public: explicit HalfStaticArray(MemoryPool& p) : Array > (p) {} - HalfStaticArray(MemoryPool& p, int InitialCapacity) : + HalfStaticArray(MemoryPool& p, size_t InitialCapacity) : Array > (p, InitialCapacity) {} HalfStaticArray() : Array > () {} - explicit HalfStaticArray(int InitialCapacity) : + explicit HalfStaticArray(size_t InitialCapacity) : Array > (InitialCapacity) {} }; diff --git a/src/common/classes/objects_array.h b/src/common/classes/objects_array.h index 69e12fb5ae..02f4e5ab77 100644 --- a/src/common/classes/objects_array.h +++ b/src/common/classes/objects_array.h @@ -43,8 +43,8 @@ namespace Firebird friend class ObjectsArray; private: ObjectsArray *lst; - int pos; - iterator(ObjectsArray *l, int p) : lst(l), pos(p) { } + size_t pos; + iterator(ObjectsArray *l, size_t p) : lst(l), pos(p) { } public: iterator() : lst(0), pos(0) { } /* @@ -82,11 +82,11 @@ namespace Firebird } }; public: - void insert(int index, const T& item) { + void insert(size_t index, const T& item) { T* dataL = FB_NEW(this->getPool()) T(this->getPool(), item); inherited::insert(index, dataL); } - int add(const T& item) { + size_t add(const T& item) { T* dataL = FB_NEW(this->getPool()) T(this->getPool(), item); return inherited::add(dataL); }; @@ -104,7 +104,7 @@ namespace Firebird delete pntr; return rc; } - void remove(int index) { + void remove(size_t index) { delete getPointer(index); inherited::remove(index); } @@ -112,8 +112,8 @@ namespace Firebird fb_assert(itr.lst == this); remove(itr.pos); } - void shrink(int newCount) { - for (int i = newCount; i < getCount(); i++) { + void shrink(size_t newCount) { + for (size_t i = newCount; i < getCount(); i++) { delete getPointer(i); } inherited::shrink(newCount); @@ -128,29 +128,29 @@ namespace Firebird fb_assert(getCount() > 0); return iterator(this, getCount() - 1); } - const T& operator[](int index) const { + const T& operator[](size_t index) const { return *getPointer(index); } - const T* getPointer(int index) const { + const T* getPointer(size_t index) const { return inherited::getElement(index); } - T& operator[](int index) { + T& operator[](size_t index) { return *getPointer(index); } - T* getPointer(int index) { + T* getPointer(size_t index) { return inherited::getElement(index); } explicit ObjectsArray(MemoryPool& p) : A(p) { } ObjectsArray() : A() { } ~ObjectsArray() { - for (int i = 0; i < getCount(); i++) { + for (size_t i = 0; i < getCount(); i++) { delete getPointer(i); } } - int getCount() const {return inherited::getCount();} - int getCapacity() const {return inherited::getCapacity();} + size_t getCount() const {return inherited::getCount();} + size_t getCapacity() const {return inherited::getCapacity();} void clear() { - for (int i = 0; i < getCount(); i++) { + for (size_t i = 0; i < getCount(); i++) { delete getPointer(i); } inherited::clear(); @@ -189,7 +189,7 @@ namespace Firebird explicit SortedObjectsArray(MemoryPool& p) : ObjectsArray >(p) { } - bool find(const Key& item, int& pos) { + bool find(const Key& item, size_t& pos) { return inherited::find(item, pos); } }; diff --git a/src/common/classes/tree.h b/src/common/classes/tree.h index 5f7b8d61ae..5f13e94399 100644 --- a/src/common/classes/tree.h +++ b/src/common/classes/tree.h @@ -24,7 +24,7 @@ * Contributor(s): ______________________________________. * * - * $Id: tree.h,v 1.35 2004-06-30 01:26:06 skidder Exp $ + * $Id: tree.h,v 1.36 2004-07-16 23:06:04 skidder Exp $ * */ @@ -314,7 +314,7 @@ public: void *list = tree->root; if (!list) return false; // Uninitalized tree for (int lev = tree->level; lev; lev--) { - int pos; + size_t pos; if (!((NodeList *)list)->find(key, pos)) if ( --pos < 0 ) pos = 0; list = (*(NodeList *)list)[pos]; @@ -391,8 +391,7 @@ public: // Accessor position must be establised via successful call to getFirst(), // getLast() or locate() before you can call this method bool getPrev() { - curPos--; - if (curPos < 0) { + if (curPos == 0) { if (curr->prev) { curr = curr->prev; curPos = curr->getCount() - 1; @@ -401,14 +400,15 @@ public: curPos = 0; return false; } - } + } else + curPos--; return true; } Value& current() const { return (*curr)[curPos]; } private: BePlusTree* tree; ItemList *curr; - int curPos; + size_t curPos; }; private: @@ -436,7 +436,7 @@ bool BePlusTree::a void *vList = this->root; const Key& key = KeyOfValue::generate(NULL, item); for (int lev = this->level; lev > 0 ; lev--) { - int pos; + size_t pos; if (!((NodeList *)vList)->find(key, pos)) if ( --pos < 0 ) pos = 0; vList = (*(NodeList *)vList)[pos]; @@ -444,7 +444,7 @@ bool BePlusTree::a ItemList *leaf = (ItemList *)vList; - int pos; + size_t pos; if (leaf->find(key, pos)) return false; if (leaf->getCount() < LeafCount) { @@ -682,7 +682,7 @@ void BePlusTree::_ } else { - int pos; + size_t pos; #ifndef DEV_BUILD list->find(NodeList::generate(list, node), pos); #else @@ -709,7 +709,7 @@ void BePlusTree::_ // After join upper levels of the tree remain stable because join doesn't change // key of the page. The same applies to lower case too. temp->join(*list); - for (int i = 0; i < list->getCount(); i++) + for (size_t i = 0; i < list->getCount(); i++) NodeList::setNodeParent((*list)[i], nodeLevel, temp); _removePage(nodeLevel + 1, list); } @@ -718,7 +718,7 @@ void BePlusTree::_ NEED_MERGE(temp->getCount() + list->getCount(), NodeCount) ) { list->join(*temp); - for (int i = 0; i < temp->getCount(); i++) + for (size_t i = 0; i < temp->getCount(); i++) NodeList::setNodeParent((*temp)[i], nodeLevel, list); _removePage(nodeLevel + 1, temp); } diff --git a/src/common/classes/vector.h b/src/common/classes/vector.h index 456209353f..4de9b2dcf3 100644 --- a/src/common/classes/vector.h +++ b/src/common/classes/vector.h @@ -24,7 +24,7 @@ * Contributor(s): ______________________________________. * * - * $Id: vector.h,v 1.10 2004-06-30 01:26:06 skidder Exp $ + * $Id: vector.h,v 1.11 2004-07-16 23:06:04 skidder Exp $ * */ @@ -37,34 +37,34 @@ namespace Firebird { // Very fast static array of simple types -template +template class Vector { public: Vector() : count(0) {} void clear() { count = 0; }; - T& operator[](int index) { + T& operator[](size_t index) { fb_assert(index >= 0 && index < count); return data[index]; } T* begin() { return data; } T* end() { return data + count; } - void insert(int index, const T& item) { + void insert(size_t index, const T& item) { fb_assert(index >= 0 && index <= count); fb_assert(count < Capacity); memmove(data + index + 1, data + index, sizeof(T) * (count++ - index)); data[index] = item; } - int add(const T& item) { + size_t add(const T& item) { fb_assert(count < Capacity); data[count++] = item; return count; }; - void remove(int index) { + void remove(size_t index) { fb_assert(index >= 0 && index < count); memmove(data + index, data + index + 1, sizeof(T) * (--count - index)); } - void shrink(int newCount) { + void shrink(size_t newCount) { fb_assert(newCount <= count); count = newCount; }; @@ -73,10 +73,10 @@ public: memcpy(data + count, L.data, sizeof(T) * L.count); count += L.count; } - int getCount() const { return count; } - int getCapacity() const { return Capacity; } + size_t getCount() const { return count; } + size_t getCapacity() const { return Capacity; } protected: - int count; + size_t count; T data[Capacity]; }; @@ -98,16 +98,16 @@ public: // Fast sorted array of simple objects // It is used for B+ tree nodes lower, but can still be used by itself -template , typename Cmp = DefaultComparator > class SortedVector : public Vector { public: SortedVector() : Vector() {} - bool find(const Key& item, int& pos) const { - int highBound = this->count, lowBound = 0; + bool find(const Key& item, size_t& pos) const { + size_t highBound = this->count, lowBound = 0; while (highBound > lowBound) { - const int temp = (highBound + lowBound) >> 1; + const size_t temp = (highBound + lowBound) >> 1; if (Cmp::greaterThan(item, KeyOfValue::generate(this, this->data[temp]))) lowBound = temp + 1; else @@ -117,8 +117,8 @@ public: return highBound != this->count && !Cmp::greaterThan(KeyOfValue::generate(this, this->data[lowBound]), item); } - int add(const Value& item) { - int pos; + size_t add(const Value& item) { + size_t pos; find(KeyOfValue::generate(this, item), pos); insert(pos, item); return pos; diff --git a/src/common/config/config_file.cpp b/src/common/config/config_file.cpp index 0316384384..431971d78e 100644 --- a/src/common/config/config_file.cpp +++ b/src/common/config/config_file.cpp @@ -98,7 +98,7 @@ string ConfigFile::getString(const string& key) { checkLoadConfig(); - int pos; + size_t pos; return parameters.find(key, pos) ? parameters[pos].second : string(); } diff --git a/src/dsql/pass1.cpp b/src/dsql/pass1.cpp index 297c311274..03254279e4 100644 --- a/src/dsql/pass1.cpp +++ b/src/dsql/pass1.cpp @@ -2080,7 +2080,7 @@ static void check_unique_fields_names(StrArray& names, const dsql_nod* fields) fb_assert(false); } - int pos; + size_t pos; if (!names.find(name, pos)) names.add(name); else { diff --git a/src/jrd/cmp.cpp b/src/jrd/cmp.cpp index a70a4a5b81..3e6b25472c 100644 --- a/src/jrd/cmp.cpp +++ b/src/jrd/cmp.cpp @@ -261,7 +261,7 @@ static void build_external_access(thread_db* tdbb, ExternalAccessList& list, jrd **************************************/ for (ExternalAccess *item = request->req_external.begin(); item < request->req_external.end(); item++) { - int i; + size_t i; if (list.find(*item, i)) continue; list.insert(i, *item); @@ -2092,10 +2092,10 @@ void CMP_post_access(thread_db* tdbb, SET_TDBB(tdbb); - int i; - AccessItem temp(security_name, view_id, name, type_name, mask); + size_t i; + if (csb->csb_access.find(temp, i)) { return; @@ -2143,7 +2143,7 @@ void CMP_post_resource( ResourceList* rsc_ptr, } // Add it into list if not present already - int pos; + size_t pos; if (!rsc_ptr->find(resource, pos)) rsc_ptr->insert(pos, resource); } @@ -5469,7 +5469,7 @@ static void post_procedure_access(thread_db* tdbb, CompilerScratch* csb, jrd_prc // Add the procedure to list of external objects accessed ExternalAccess temp(procedure->prc_id); - int idx; + size_t idx; if (!csb->csb_external.find(temp, idx)) csb->csb_external.insert(idx, temp); } @@ -5577,7 +5577,7 @@ static void post_trigger_access(CompilerScratch* csb, // Post trigger access ExternalAccess temp(operation, owner_relation->rel_id, view ? view->rel_id : 0); - int i; + size_t i; if (!csb->csb_external.find(temp, i)) csb->csb_external.insert(i, temp); } diff --git a/src/jrd/intl.cpp b/src/jrd/intl.cpp index 00c2ac242f..37f9a7890b 100644 --- a/src/jrd/intl.cpp +++ b/src/jrd/intl.cpp @@ -297,7 +297,7 @@ CharSetContainer::CharSetContainer(MemoryPool& p, USHORT cs_id) : CsConvert CharSetContainer::lookupConverter(thread_db* tdbb, CHARSET_ID to_cs) { - int pos; + size_t pos; if (charset_converters.find(to_cs, pos)) return charset_converters[pos]; if (impossible_conversions.find(to_cs, pos)) diff --git a/src/jrd/plugin_manager.cpp b/src/jrd/plugin_manager.cpp index a4d66607b3..199a8223e5 100644 --- a/src/jrd/plugin_manager.cpp +++ b/src/jrd/plugin_manager.cpp @@ -261,7 +261,7 @@ PluginManager::Module::~Module() void *PluginManager::BuiltinModule::lookupSymbol(const Firebird::string& symbol) { - int n; + size_t n; if (! symbols.find(symbol, n)) return 0; return symbols[n].second; diff --git a/src/jrd/rpb_chain.cpp b/src/jrd/rpb_chain.cpp index 44e064b901..d9d9a9aef0 100644 --- a/src/jrd/rpb_chain.cpp +++ b/src/jrd/rpb_chain.cpp @@ -64,7 +64,7 @@ bool traRpbList::PopRpb(record_param* value, int Level) if (Level < 0) { return false; } - int pos = -1; + size_t pos; ExecAssert(find(traRpbListElement(value, Level), pos)); const bool rc = (*this)[pos].lr_rpb->rpb_stream_flags & RPB_s_refetch; remove(pos); diff --git a/src/jrd/tra.cpp b/src/jrd/tra.cpp index ad236132e5..4cdc085274 100644 --- a/src/jrd/tra.cpp +++ b/src/jrd/tra.cpp @@ -766,7 +766,7 @@ void TRA_post_resources(thread_db* tdbb, jrd_tra* transaction, ResourceList& res if (rsc->rsc_type == Resource::rsc_relation || rsc->rsc_type == Resource::rsc_procedure) { - int i; + size_t i; if (!transaction->tra_resources.find(*rsc, i)) { transaction->tra_resources.insert(i, *rsc);