From 2ca793f2d852210bee36a8e4ec5e2a456f61432a Mon Sep 17 00:00:00 2001 From: ALANVF Date: Wed, 21 Apr 2021 20:02:48 -0400 Subject: [PATCH 1/6] Add regexp_matched_num --- include/hx/StdLibs.h | 1 + src/hx/libs/regexp/RegExp.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/hx/StdLibs.h b/include/hx/StdLibs.h index 7c3385c90..a9ebade57 100644 --- a/include/hx/StdLibs.h +++ b/include/hx/StdLibs.h @@ -533,6 +533,7 @@ HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic _hx_regexp_new_options(String s, String op HXCPP_EXTERN_CLASS_ATTRIBUTES bool _hx_regexp_match(Dynamic handle, String string, int pos, int len); HXCPP_EXTERN_CLASS_ATTRIBUTES String _hx_regexp_matched(Dynamic handle, int pos); HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic _hx_regexp_matched_pos(Dynamic handle, int match); +HXCPP_EXTERN_CLASS_ATTRIBUTES int _hx_regexp_matched_num(Dynamic handle); // haxe.zip.(Un)Compress.hx -> src/hx/libs/zlib/ZLib.cpp diff --git a/src/hx/libs/regexp/RegExp.cpp b/src/hx/libs/regexp/RegExp.cpp index 4dce05708..fff395815 100644 --- a/src/hx/libs/regexp/RegExp.cpp +++ b/src/hx/libs/regexp/RegExp.cpp @@ -244,4 +244,19 @@ Dynamic _hx_regexp_matched_pos(Dynamic handle, int m) ->setFixed(1,HX_("pos",94,5d,55,00),start); } +/** + regexp_matched_num : 'regexp -> int + Return the total number of matched groups, or -1 if the regexp has not + been matched yet +**/ +int _hx_regexp_matched_num(Dynamic handle) +{ + pcredata *d = PCRE(handle); + + if( !d->string.raw_ptr() ) + return -1; + else + return d->nmatchs; +} + From 76b9be9a4e54e263f6b74974862180a640b23503 Mon Sep 17 00:00:00 2001 From: ALANVF Date: Thu, 22 Apr 2021 08:30:37 -0400 Subject: [PATCH 2/6] add __X_hash_size --- include/hx/StdLibs.h | 3 +++ src/hx/Hash.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/hx/StdLibs.h b/include/hx/StdLibs.h index a9ebade57..07fab2daf 100644 --- a/include/hx/StdLibs.h +++ b/include/hx/StdLibs.h @@ -173,6 +173,7 @@ HXCPP_EXTERN_CLASS_ATTRIBUTES void __int_hash_set_string(HX_MAP_THIS_AR HXCPP_EXTERN_CLASS_ATTRIBUTES void __int_hash_set_float(HX_MAP_THIS_ARG,int inKey,Float inValue); HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __int_hash_to_string(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES void __int_hash_clear(Dynamic &hash); +HXCPP_EXTERN_CLASS_ATTRIBUTES int __int_hash_size(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic __int_hash_get(Dynamic inHash,int inKey); HXCPP_EXTERN_CLASS_ATTRIBUTES int __int_hash_get_int(Dynamic inHash,int inKey); @@ -196,6 +197,7 @@ HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __string_hash_map_substr(HX_MAP_THIS HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __string_hash_to_string(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __string_hash_to_string_raw(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES void __string_hash_clear(Dynamic &hash); +HXCPP_EXTERN_CLASS_ATTRIBUTES int __string_hash_size(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic __string_hash_get(Dynamic inHash,String inKey); HXCPP_EXTERN_CLASS_ATTRIBUTES int __string_hash_get_int(Dynamic inHash,String inKey); @@ -216,6 +218,7 @@ HXCPP_EXTERN_CLASS_ATTRIBUTES void __object_hash_set_string(HX_MAP_THIS HXCPP_EXTERN_CLASS_ATTRIBUTES void __object_hash_set_float(HX_MAP_THIS_ARG,Dynamic inKey,Float inValue,bool inWeakKey=false); HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __object_hash_to_string(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES void __object_hash_clear(Dynamic &hash); +HXCPP_EXTERN_CLASS_ATTRIBUTES int __object_hash_size(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic __object_hash_get(Dynamic inHash,Dynamic inKey); diff --git a/src/hx/Hash.cpp b/src/hx/Hash.cpp index e9a740293..fe931ff86 100644 --- a/src/hx/Hash.cpp +++ b/src/hx/Hash.cpp @@ -238,6 +238,15 @@ void __int_hash_clear(Dynamic &ioHash) hash->clear(); } +int __int_hash_size(Dynamic &ioHash) +{ + IntHashBase *hash = static_cast(ioHash.GetPtr()); + if(!hash) + return 0; + return ((IntHashObject *) hash)->getSize(); +} + + // --- StringHash ---------------------------------------------------- @@ -547,6 +556,14 @@ void __string_hash_clear(Dynamic &ioHash) hash->clear(); } +int __string_hash_size(Dynamic &ioHash) +{ + StringHashBase *hash = static_cast(ioHash.GetPtr()); + if(!hash) + return 0; + return ((StringHashObject *) hash)->getSize(); +} + @@ -823,3 +840,11 @@ void __object_hash_clear(Dynamic &ioHash) hash->clear(); } +int __object_hash_size(Dynamic &ioHash) +{ + DynamicHashBase *hash = static_cast(ioHash.GetPtr()); + if(!hash) + return 0; + return ((DynamicHashObject *) hash)->getSize(); +} + From 78de80b0c74fb1c628d5e99b8d910d071d762c07 Mon Sep 17 00:00:00 2001 From: ALANVF Date: Fri, 30 Apr 2021 14:49:43 -0400 Subject: [PATCH 3/6] Use option 4 for hash size --- include/hx/StdLibs.h | 4 ++++ src/hx/Hash.cpp | 37 +++++++++++-------------------------- src/hx/Hash.h | 17 +++++++++-------- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/include/hx/StdLibs.h b/include/hx/StdLibs.h index 07fab2daf..5dba85006 100644 --- a/include/hx/StdLibs.h +++ b/include/hx/StdLibs.h @@ -159,6 +159,10 @@ HXCPP_EXTERN_CLASS_ATTRIBUTES String __hxcpp_utf8_string_to_char_bytes(String &i #define HX_MAP_THIS_ARG Dynamic &ioHash #endif +// --- HashRoot --------------------------------------------------------------------- + +HXCPP_EXTERN_CLASS_ATTRIBUTES int __root_hash_size(Dynamic *rtHash); + // --- IntHash ---------------------------------------------------------------------- HXCPP_EXTERN_CLASS_ATTRIBUTES inline hx::Object *__int_hash_create() { return 0; } diff --git a/src/hx/Hash.cpp b/src/hx/Hash.cpp index fe931ff86..6bd65f338 100644 --- a/src/hx/Hash.cpp +++ b/src/hx/Hash.cpp @@ -5,6 +5,17 @@ using namespace hx; +// --- HashRoot --------------------------------------------------- + +int __root_hash_size(Dynamic &rtHash) +{ + HashRoot *hash = static_cast(rtHash.GetPtr()); + if(!hash) + return 0; + return hash->getSize(); +} + + // --- IntHash ---------------------------------------------------- namespace @@ -238,15 +249,6 @@ void __int_hash_clear(Dynamic &ioHash) hash->clear(); } -int __int_hash_size(Dynamic &ioHash) -{ - IntHashBase *hash = static_cast(ioHash.GetPtr()); - if(!hash) - return 0; - return ((IntHashObject *) hash)->getSize(); -} - - // --- StringHash ---------------------------------------------------- @@ -556,15 +558,6 @@ void __string_hash_clear(Dynamic &ioHash) hash->clear(); } -int __string_hash_size(Dynamic &ioHash) -{ - StringHashBase *hash = static_cast(ioHash.GetPtr()); - if(!hash) - return 0; - return ((StringHashObject *) hash)->getSize(); -} - - // --- ObjectHash ---------------------------------------------------- @@ -840,11 +833,3 @@ void __object_hash_clear(Dynamic &ioHash) hash->clear(); } -int __object_hash_size(Dynamic &ioHash) -{ - DynamicHashBase *hash = static_cast(ioHash.GetPtr()); - if(!hash) - return 0; - return ((DynamicHashObject *) hash)->getSize(); -} - diff --git a/src/hx/Hash.h b/src/hx/Hash.h index a49584446..bd9f8903d 100644 --- a/src/hx/Hash.h +++ b/src/hx/Hash.h @@ -218,10 +218,15 @@ template inline void CopyValue(null &, const T &) { } struct HashRoot : public Object { HashStore store; + int size; + int mask; + int bucketCount; HX_IS_INSTANCE_OF enum { _hx_ClassId = hx::clsIdHash }; virtual void updateAfterGc() = 0; + + inline int getSize() { return size; } }; template @@ -230,6 +235,9 @@ struct HashBase : public HashRoot HashBase(int inStore) { store = (HashStore)inStore; + size = 0; + mask = 0; + bucketCount = 0; } @@ -276,22 +284,15 @@ struct Hash : public HashBase< typename ELEMENT::Key > enum { IgnoreHash = Element::IgnoreHash }; - int size; - int mask; - int bucketCount; - ELEMENT **bucket; + ELEMENT **bucket; Hash() : HashBase( StoreOf::store ) { bucket = 0; - size = 0; - mask = 0; - bucketCount = 0; if (ELEMENT::WeakKeys && Element::ManageKeys) RegisterWeakHash(this); } - inline int getSize() { return size; } template bool TIsWeakRefValid(T &) { return true; } From 89590d8e35ae7932118be49aea934908aa9a66fd Mon Sep 17 00:00:00 2001 From: ALANVF Date: Fri, 30 Apr 2021 15:43:47 -0400 Subject: [PATCH 4/6] members need this-> now --- src/hx/Hash.h | 70 +++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/hx/Hash.h b/src/hx/Hash.h index bd9f8903d..7a0c0a880 100644 --- a/src/hx/Hash.h +++ b/src/hx/Hash.h @@ -304,7 +304,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > { if (Element::WeakKeys && Element::ManageKeys) { - for(int b=0;bbucketCount;b++) { Element **headPtr = &bucket[b]; while(*headPtr) @@ -313,7 +313,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > if (!TIsWeakRefValid(el.key)) { *headPtr = el.next; - size--; + this->size--; } else headPtr = &el.next; @@ -327,9 +327,9 @@ struct Hash : public HashBase< typename ELEMENT::Key > #ifdef HXCPP_TELEMETRY bool is_new = bucket==0; #endif - mask = inNewCount-1; + this->mask = inNewCount-1; //printf("expand %d -> %d\n",bucketCount, inNewCount); - bucket = (Element **)InternalRealloc(bucketCount*sizeof(ELEMENT *), bucket,inNewCount*sizeof(ELEMENT *)); + bucket = (Element **)InternalRealloc(this->bucketCount*sizeof(ELEMENT *), bucket,inNewCount*sizeof(ELEMENT *)); HX_OBJ_WB_GET(this, bucket); //for(int b=bucketCount;b #endif - for(int b=0;bbucketCount;b++) { Element **head = &bucket[b]; while(*head) { Element &e = **head; - int newBucket = e.getHash()&mask; + int newBucket = e.getHash()&this->mask; if ( newBucket != b ) { *head = e.next; @@ -357,7 +357,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > } } - bucketCount = inNewCount; + this->bucketCount = inNewCount; } void reserve(int inSize) @@ -370,11 +370,11 @@ struct Hash : public HashBase< typename ELEMENT::Key > void compact() { - int origSize = bucketCount; - int newSize = bucketCount>>1; + int origSize = this->bucketCount; + int newSize = this->bucketCount>>1; // printf("compact -> %d\n", newSize); - mask = newSize-1; - for(int b=newSize; bmask = newSize-1; + for(int b=newSize; bbucketCount; b++) { Element *head = bucket[b]; if (head) @@ -393,8 +393,8 @@ struct Hash : public HashBase< typename ELEMENT::Key > bucket[b] = 0; } } - bucketCount = newSize; - bucket = (Element **)InternalRealloc(origSize*sizeof(ELEMENT *),bucket, sizeof(ELEMENT *)*bucketCount ); + this->bucketCount = newSize; + bucket = (Element **)InternalRealloc(origSize*sizeof(ELEMENT *),bucket, sizeof(ELEMENT *)*this->bucketCount ); HX_OBJ_WB_GET(this, bucket); } @@ -403,15 +403,15 @@ struct Hash : public HashBase< typename ELEMENT::Key > if (!bucket) return false; unsigned int hash = HashCalcHash(inKey); - Element **head = bucket + (hash&mask); + Element **head = bucket + (hash&this->mask); while(*head) { Element &el = **head; if ( (IgnoreHash || el.getHash()==hash) && el.key==inKey) { *head = el.next; - size--; - if (bucketCount>8 && size < (bucketCount>>1) ) + this->size--; + if (this->bucketCount>8 && this->size < (this->bucketCount>>1) ) compact(); return true; } @@ -423,8 +423,8 @@ struct Hash : public HashBase< typename ELEMENT::Key > ELEMENT *allocElement() { ELEMENT *result = (ELEMENT *)InternalNew( sizeof(ELEMENT), false ); - size++; - expandBuckets(size); + this->size++; + expandBuckets(this->size); return result; } @@ -432,15 +432,15 @@ struct Hash : public HashBase< typename ELEMENT::Key > { // Trades memory vs bucket occupancy - more memory is used for elements anyhow, so not too critical enum { LOG_ELEMS_PER_BUCKET = 1 }; - if ( inSize > (bucketCount< (this->bucketCount<bucketCount; if (newCount==0) newCount = 2; else while( inSize > (newCount<bucketCount) rebucket(newCount); } } @@ -448,7 +448,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > Element *find(int inHash, Key inKey) { if (!bucket) return 0; - Element *head = bucket[inHash & mask]; + Element *head = bucket[inHash & this->mask]; while(head) { if ( (IgnoreHash || head->getHash()==inHash) && head->key==inKey) @@ -509,7 +509,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > bool findEquivalentKey(Key &outKey, int inHash, const Finder &inFinder) { if (!bucket) return false; - Element *head = bucket[inHash & mask]; + Element *head = bucket[inHash & this->mask]; while(head) { if ( (IgnoreHash || head->getHash()==inHash) && inFinder==head->key) @@ -542,8 +542,8 @@ struct Hash : public HashBase< typename ELEMENT::Key > el = allocElement(); el->setKey(inKey,hash); CopyValue(el->value,inValue); - el->next = bucket[hash&mask]; - bucket[hash&mask] = el; + el->next = bucket[hash&this->mask]; + bucket[hash&this->mask] = el; #ifdef HXCPP_GC_GENERATIONAL unsigned char &mark = ((unsigned char *)(this))[ HX_ENDIAN_MARK_ID_BYTE]; @@ -569,16 +569,16 @@ struct Hash : public HashBase< typename ELEMENT::Key > void clear() { bucket = 0; - size = 0; - mask = 0; - bucketCount = 0; + this->size = 0; + this->mask = 0; + this->bucketCount = 0; } template void iterate(F &inFunc) { - for(int b=0;bbucketCount;b++) { Element *el = bucket[b]; while(el) @@ -609,7 +609,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > { Hash *result = new Hash(); - result->reserve(getSize()*3/2); + result->reserve(this->getSize()*3/2); Converter< Hash > converter(result); @@ -636,7 +636,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > }; Array keys() { - KeyBuilder builder(getSize()); + KeyBuilder builder(this->getSize()); iterate(builder); return builder.array;; } @@ -658,7 +658,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > }; Dynamic values() { - ValueBuilder builder(getSize()); + ValueBuilder builder(this->getSize()); iterate(builder); return builder.array;; } @@ -695,7 +695,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > String toString() { - StringBuilder builder(getSize()); + StringBuilder builder(this->getSize()); iterate(builder); return builder.toString(); } @@ -703,7 +703,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > String toStringRaw() { - StringBuilder builder(getSize(),true); + StringBuilder builder(this->getSize(),true); iterate(builder); return builder.toString(); } @@ -739,7 +739,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > { //printf(" visit hash %p\n", this); HX_VISIT_ARRAY(bucket); - for(int b=0;bbucketCount;b++) { HX_VISIT_ARRAY(bucket[b]); Element *el = bucket[b]; From f172fc1eb377acb0c15703eb572e85a3bdba1d1c Mon Sep 17 00:00:00 2001 From: ALANVF Date: Sun, 30 May 2021 14:30:11 -0400 Subject: [PATCH 5/6] Clean up code --- include/hx/StdLibs.h | 3 -- src/hx/Hash.h | 74 +++++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/include/hx/StdLibs.h b/include/hx/StdLibs.h index 5dba85006..515aeef4b 100644 --- a/include/hx/StdLibs.h +++ b/include/hx/StdLibs.h @@ -177,7 +177,6 @@ HXCPP_EXTERN_CLASS_ATTRIBUTES void __int_hash_set_string(HX_MAP_THIS_AR HXCPP_EXTERN_CLASS_ATTRIBUTES void __int_hash_set_float(HX_MAP_THIS_ARG,int inKey,Float inValue); HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __int_hash_to_string(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES void __int_hash_clear(Dynamic &hash); -HXCPP_EXTERN_CLASS_ATTRIBUTES int __int_hash_size(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic __int_hash_get(Dynamic inHash,int inKey); HXCPP_EXTERN_CLASS_ATTRIBUTES int __int_hash_get_int(Dynamic inHash,int inKey); @@ -201,7 +200,6 @@ HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __string_hash_map_substr(HX_MAP_THIS HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __string_hash_to_string(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __string_hash_to_string_raw(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES void __string_hash_clear(Dynamic &hash); -HXCPP_EXTERN_CLASS_ATTRIBUTES int __string_hash_size(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic __string_hash_get(Dynamic inHash,String inKey); HXCPP_EXTERN_CLASS_ATTRIBUTES int __string_hash_get_int(Dynamic inHash,String inKey); @@ -222,7 +220,6 @@ HXCPP_EXTERN_CLASS_ATTRIBUTES void __object_hash_set_string(HX_MAP_THIS HXCPP_EXTERN_CLASS_ATTRIBUTES void __object_hash_set_float(HX_MAP_THIS_ARG,Dynamic inKey,Float inValue,bool inWeakKey=false); HXCPP_EXTERN_CLASS_ATTRIBUTES ::String __object_hash_to_string(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES void __object_hash_clear(Dynamic &hash); -HXCPP_EXTERN_CLASS_ATTRIBUTES int __object_hash_size(Dynamic &hash); HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic __object_hash_get(Dynamic inHash,Dynamic inKey); diff --git a/src/hx/Hash.h b/src/hx/Hash.h index 7a0c0a880..5638d5953 100644 --- a/src/hx/Hash.h +++ b/src/hx/Hash.h @@ -276,6 +276,10 @@ template<> struct ArrayValueOf { typedef Dynamic Value; }; template struct Hash : public HashBase< typename ELEMENT::Key > { + using HashRoot::size; + using HashRoot::mask; + using HashRoot::bucketCount; + typedef typename ELEMENT::Key Key; typedef typename ELEMENT::Value Value; typedef typename ArrayValueOf::Value ArrayValue; @@ -304,7 +308,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > { if (Element::WeakKeys && Element::ManageKeys) { - for(int b=0;bbucketCount;b++) + for(int b=0;b if (!TIsWeakRefValid(el.key)) { *headPtr = el.next; - this->size--; + size--; } else headPtr = &el.next; @@ -327,9 +331,9 @@ struct Hash : public HashBase< typename ELEMENT::Key > #ifdef HXCPP_TELEMETRY bool is_new = bucket==0; #endif - this->mask = inNewCount-1; + mask = inNewCount-1; //printf("expand %d -> %d\n",bucketCount, inNewCount); - bucket = (Element **)InternalRealloc(this->bucketCount*sizeof(ELEMENT *), bucket,inNewCount*sizeof(ELEMENT *)); + bucket = (Element **)InternalRealloc(bucketCount*sizeof(ELEMENT *), bucket,inNewCount*sizeof(ELEMENT *)); HX_OBJ_WB_GET(this, bucket); //for(int b=bucketCount;b #endif - for(int b=0;bbucketCount;b++) + for(int b=0;bmask; + int newBucket = e.getHash()&mask; if ( newBucket != b ) { *head = e.next; @@ -357,7 +361,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > } } - this->bucketCount = inNewCount; + bucketCount = inNewCount; } void reserve(int inSize) @@ -370,11 +374,11 @@ struct Hash : public HashBase< typename ELEMENT::Key > void compact() { - int origSize = this->bucketCount; - int newSize = this->bucketCount>>1; + int origSize = bucketCount; + int newSize = bucketCount>>1; // printf("compact -> %d\n", newSize); - this->mask = newSize-1; - for(int b=newSize; bbucketCount; b++) + mask = newSize-1; + for(int b=newSize; b bucket[b] = 0; } } - this->bucketCount = newSize; - bucket = (Element **)InternalRealloc(origSize*sizeof(ELEMENT *),bucket, sizeof(ELEMENT *)*this->bucketCount ); + bucketCount = newSize; + bucket = (Element **)InternalRealloc(origSize*sizeof(ELEMENT *),bucket, sizeof(ELEMENT *)*bucketCount ); HX_OBJ_WB_GET(this, bucket); } @@ -403,15 +407,15 @@ struct Hash : public HashBase< typename ELEMENT::Key > if (!bucket) return false; unsigned int hash = HashCalcHash(inKey); - Element **head = bucket + (hash&this->mask); + Element **head = bucket + (hash&mask); while(*head) { Element &el = **head; if ( (IgnoreHash || el.getHash()==hash) && el.key==inKey) { *head = el.next; - this->size--; - if (this->bucketCount>8 && this->size < (this->bucketCount>>1) ) + size--; + if (bucketCount>8 && size < (bucketCount>>1) ) compact(); return true; } @@ -423,8 +427,8 @@ struct Hash : public HashBase< typename ELEMENT::Key > ELEMENT *allocElement() { ELEMENT *result = (ELEMENT *)InternalNew( sizeof(ELEMENT), false ); - this->size++; - expandBuckets(this->size); + size++; + expandBuckets(size); return result; } @@ -432,15 +436,15 @@ struct Hash : public HashBase< typename ELEMENT::Key > { // Trades memory vs bucket occupancy - more memory is used for elements anyhow, so not too critical enum { LOG_ELEMS_PER_BUCKET = 1 }; - if ( inSize > (this->bucketCount< (bucketCount<bucketCount; + int newCount = bucketCount; if (newCount==0) newCount = 2; else while( inSize > (newCount<bucketCount) + if (newCount!=bucketCount) rebucket(newCount); } } @@ -448,7 +452,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > Element *find(int inHash, Key inKey) { if (!bucket) return 0; - Element *head = bucket[inHash & this->mask]; + Element *head = bucket[inHash & mask]; while(head) { if ( (IgnoreHash || head->getHash()==inHash) && head->key==inKey) @@ -509,7 +513,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > bool findEquivalentKey(Key &outKey, int inHash, const Finder &inFinder) { if (!bucket) return false; - Element *head = bucket[inHash & this->mask]; + Element *head = bucket[inHash & mask]; while(head) { if ( (IgnoreHash || head->getHash()==inHash) && inFinder==head->key) @@ -542,8 +546,8 @@ struct Hash : public HashBase< typename ELEMENT::Key > el = allocElement(); el->setKey(inKey,hash); CopyValue(el->value,inValue); - el->next = bucket[hash&this->mask]; - bucket[hash&this->mask] = el; + el->next = bucket[hash&mask]; + bucket[hash&mask] = el; #ifdef HXCPP_GC_GENERATIONAL unsigned char &mark = ((unsigned char *)(this))[ HX_ENDIAN_MARK_ID_BYTE]; @@ -569,16 +573,16 @@ struct Hash : public HashBase< typename ELEMENT::Key > void clear() { bucket = 0; - this->size = 0; - this->mask = 0; - this->bucketCount = 0; + size = 0; + mask = 0; + bucketCount = 0; } template void iterate(F &inFunc) { - for(int b=0;bbucketCount;b++) + for(int b=0;b { Hash *result = new Hash(); - result->reserve(this->getSize()*3/2); + result->reserve(getSize()*3/2); Converter< Hash > converter(result); @@ -636,7 +640,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > }; Array keys() { - KeyBuilder builder(this->getSize()); + KeyBuilder builder(getSize()); iterate(builder); return builder.array;; } @@ -658,7 +662,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > }; Dynamic values() { - ValueBuilder builder(this->getSize()); + ValueBuilder builder(getSize()); iterate(builder); return builder.array;; } @@ -695,7 +699,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > String toString() { - StringBuilder builder(this->getSize()); + StringBuilder builder(getSize()); iterate(builder); return builder.toString(); } @@ -703,7 +707,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > String toStringRaw() { - StringBuilder builder(this->getSize(),true); + StringBuilder builder(getSize(),true); iterate(builder); return builder.toString(); } @@ -739,7 +743,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > { //printf(" visit hash %p\n", this); HX_VISIT_ARRAY(bucket); - for(int b=0;bbucketCount;b++) + for(int b=0;b Date: Sun, 30 May 2021 14:59:50 -0400 Subject: [PATCH 6/6] Fix that --- src/hx/Hash.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hx/Hash.h b/src/hx/Hash.h index 5638d5953..bb5ec1c22 100644 --- a/src/hx/Hash.h +++ b/src/hx/Hash.h @@ -279,6 +279,7 @@ struct Hash : public HashBase< typename ELEMENT::Key > using HashRoot::size; using HashRoot::mask; using HashRoot::bucketCount; + using HashRoot::getSize; typedef typename ELEMENT::Key Key; typedef typename ELEMENT::Value Value;