diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-01-11 08:53:31 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-01-11 08:54:17 -0300 |
commit | e6583117df95373cffb12105de82d3816ca09f85 (patch) | |
tree | 9953c32a4b50db9cc99d0999c7904a27748a0ace /core | |
parent | 57166cd2923cc6d32b37c34f6ca2f32f6941e4a8 (diff) | |
download | redot-engine-e6583117df95373cffb12105de82d3816ca09f85.tar.gz |
Both Array and Dictionary are always in shared mode (removed copy on write).
Diffstat (limited to 'core')
-rw-r--r-- | core/array.cpp | 22 | ||||
-rw-r--r-- | core/array.h | 4 | ||||
-rw-r--r-- | core/dictionary.cpp | 32 | ||||
-rw-r--r-- | core/dictionary.h | 7 | ||||
-rw-r--r-- | core/io/json.cpp | 4 | ||||
-rw-r--r-- | core/io/marshalls.cpp | 12 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 8 | ||||
-rw-r--r-- | core/variant.cpp | 4 | ||||
-rw-r--r-- | core/variant_call.cpp | 4 | ||||
-rw-r--r-- | core/variant_op.cpp | 6 |
10 files changed, 30 insertions, 73 deletions
diff --git a/core/array.cpp b/core/array.cpp index 50cc9eee47..b9c8f543da 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -36,7 +36,6 @@ struct ArrayPrivate { SafeRefCount refcount; Vector<Variant> array; - bool shared; }; void Array::_ref(const Array& p_from) const { @@ -54,20 +53,9 @@ void Array::_ref(const Array& p_from) const { _unref(); - if (_fp->shared) { + _p = p_from._p; - _p = p_from._p; - } else { - - _p = memnew( ArrayPrivate ); - _p->shared=false; - _p->refcount.init(); - _p->array=_fp->array; - - if (_fp->refcount.unref()) - memdelete(_fp); - } } void Array::_unref() const { @@ -106,10 +94,6 @@ void Array::clear() { _p->array.clear(); } -bool Array::is_shared() const { - - return _p->shared; -} bool Array::operator==(const Array& p_array) const { @@ -316,11 +300,11 @@ Array::Array(const Array& p_from) { _ref(p_from); } -Array::Array(bool p_shared) { +Array::Array() { _p = memnew( ArrayPrivate ); _p->refcount.init(); - _p->shared=p_shared; + } Array::~Array() { diff --git a/core/array.h b/core/array.h index af57940d79..16ab16002c 100644 --- a/core/array.h +++ b/core/array.h @@ -53,8 +53,6 @@ public: bool empty() const; void clear(); - bool is_shared() const; - bool operator==(const Array& p_array) const; uint32_t hash() const; @@ -87,7 +85,7 @@ public: Variant pop_front(); Array(const Array& p_from); - Array(bool p_shared=false); + Array(); ~Array(); }; diff --git a/core/dictionary.cpp b/core/dictionary.cpp index d5d29ca0fc..3b4d3b65d0 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -49,7 +49,6 @@ struct DictionaryPrivate { SafeRefCount refcount; HashMap<Variant,Data,_DictionaryVariantHash> variant_map; int counter; - bool shared; }; @@ -79,23 +78,8 @@ void Dictionary::get_key_list( List<Variant> *p_keys) const { } -void Dictionary::_copy_on_write() const { - - //make a copy of what we have - if (_p->shared) - return; - - DictionaryPrivate *p = memnew(DictionaryPrivate); - p->shared=_p->shared; - p->variant_map=_p->variant_map; - p->refcount.init(); - _unref(); - _p=p; -} - Variant& Dictionary::operator[](const Variant& p_key) { - _copy_on_write(); DictionaryPrivate::Data *v =_p->variant_map.getptr(p_key); @@ -126,7 +110,6 @@ const Variant* Dictionary::getptr(const Variant& p_key) const { Variant* Dictionary::getptr(const Variant& p_key) { - _copy_on_write(); DictionaryPrivate::Data *v =_p->variant_map.getptr(p_key); if (!v) return NULL; @@ -171,7 +154,8 @@ bool Dictionary::has_all(const Array& p_keys) const { } void Dictionary::erase(const Variant& p_key) { - _copy_on_write(); + + _p->variant_map.erase(p_key); } @@ -199,16 +183,10 @@ void Dictionary::_ref(const Dictionary& p_from) const { void Dictionary::clear() { - _copy_on_write(); _p->variant_map.clear(); _p->counter=0; } -bool Dictionary::is_shared() const { - - return _p->shared; -} - void Dictionary::_unref() const { @@ -278,7 +256,7 @@ const Variant* Dictionary::next(const Variant* p_key) const { Dictionary Dictionary::copy() const { - Dictionary n(is_shared()); + Dictionary n; List<Variant> keys; get_key_list(&keys); @@ -304,12 +282,12 @@ Dictionary::Dictionary(const Dictionary& p_from) { } -Dictionary::Dictionary(bool p_shared) { +Dictionary::Dictionary() { _p=memnew( DictionaryPrivate ); _p->refcount.init(); _p->counter=0; - _p->shared=p_shared; + } Dictionary::~Dictionary() { diff --git a/core/dictionary.h b/core/dictionary.h index 9fab653470..a1bf291d6b 100644 --- a/core/dictionary.h +++ b/core/dictionary.h @@ -43,7 +43,7 @@ class Dictionary { mutable DictionaryPrivate *_p; - void _copy_on_write() const; + void _ref(const Dictionary& p_from) const; void _unref() const; public: @@ -62,9 +62,6 @@ public: bool empty() const; void clear(); - - bool is_shared() const; - bool has(const Variant& p_key) const; bool has_all(const Array& p_keys) const; @@ -83,7 +80,7 @@ public: Dictionary copy() const; Dictionary(const Dictionary& p_from); - Dictionary(bool p_shared=false); + Dictionary(); ~Dictionary(); }; diff --git a/core/io/json.cpp b/core/io/json.cpp index ed1e74967b..c0aa530a12 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -288,7 +288,7 @@ Error JSON::_parse_value(Variant &value,Token& token,const CharType *p_str,int & if (token.type==TK_CURLY_BRACKET_OPEN) { - Dictionary d(true); + Dictionary d; Error err = _parse_object(d,p_str,index,p_len,line,r_err_str); if (err) return err; @@ -296,7 +296,7 @@ Error JSON::_parse_value(Variant &value,Token& token,const CharType *p_str,int & return OK; } else if (token.type==TK_BRACKET_OPEN) { - Array a(true); + Array a; Error err = _parse_array(a,p_str,index,p_len,line,r_err_str); if (err) return err; diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 67baa117cb..e958edc93e 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -471,7 +471,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA); uint32_t count = decode_uint32(buf); - bool shared = count&0x80000000; + // bool shared = count&0x80000000; count&=0x7FFFFFFF; buf+=4; @@ -481,7 +481,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * (*r_len)+=4; } - Dictionary d(shared); + Dictionary d; for(uint32_t i=0;i<count;i++) { @@ -516,7 +516,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA); uint32_t count = decode_uint32(buf); - bool shared = count&0x80000000; + // bool shared = count&0x80000000; count&=0x7FFFFFFF; buf+=4; @@ -526,7 +526,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * (*r_len)+=4; } - Array varr(shared); + Array varr; for(uint32_t i=0;i<count;i++) { @@ -1232,7 +1232,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) { Dictionary d = p_variant; if (buf) { - encode_uint32(uint32_t(d.size())|(d.is_shared()?0x80000000:0),buf); + encode_uint32(uint32_t(d.size()),buf); buf+=4; } r_len+=4; @@ -1275,7 +1275,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) { Array v = p_variant; if (buf) { - encode_uint32(uint32_t(v.size())|(v.is_shared()?0x80000000:0),buf); + encode_uint32(uint32_t(v.size()),buf); buf+=4; } diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 7383fd7f6d..c093b087b8 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -426,7 +426,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) { case VARIANT_DICTIONARY: { uint32_t len=f->get_32(); - Dictionary d(len&0x80000000); //last bit means shared + Dictionary d; //last bit means shared len&=0x7FFFFFFF; for(uint32_t i=0;i<len;i++) { Variant key; @@ -442,7 +442,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) { case VARIANT_ARRAY: { uint32_t len=f->get_32(); - Array a(len&0x80000000); //last bit means shared + Array a; //last bit means shared len&=0x7FFFFFFF; a.resize(len); for(uint32_t i=0;i<len;i++) { @@ -1701,7 +1701,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property, f->store_32(VARIANT_DICTIONARY); Dictionary d = p_property; - f->store_32(uint32_t(d.size())|(d.is_shared()?0x80000000:0)); + f->store_32(uint32_t(d.size())); List<Variant> keys; d.get_key_list(&keys); @@ -1721,7 +1721,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property, f->store_32(VARIANT_ARRAY); Array a=p_property; - f->store_32(uint32_t(a.size())|(a.is_shared()?0x80000000:0)); + f->store_32(uint32_t(a.size())); for(int i=0;i<a.size();i++) { write_variant(a[i]); diff --git a/core/variant.cpp b/core/variant.cpp index 4ab46edf75..5a670a2786 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -2985,8 +2985,8 @@ bool Variant::is_shared() const { switch(type) { case OBJECT: return true; - case ARRAY: return reinterpret_cast<const Array*>(_data._mem)->is_shared(); - case DICTIONARY: return reinterpret_cast<const Dictionary*>(_data._mem)->is_shared(); + case ARRAY: return true; + case DICTIONARY: return true; default: {} } diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 9a61dd73df..0c8b40539d 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -489,7 +489,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM0(Array,sort); VCALL_LOCALMEM2(Array,sort_custom); VCALL_LOCALMEM0(Array,invert); - VCALL_LOCALMEM0R(Array,is_shared); + static void _call_PoolByteArray_get_string_from_ascii(Variant& r_ret,Variant& p_self,const Variant** p_args) { @@ -1588,7 +1588,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(ARRAY,NIL,Array,sort,varray()); ADDFUNC2(ARRAY,NIL,Array,sort_custom,OBJECT,"obj",STRING,"func",varray()); ADDFUNC0(ARRAY,NIL,Array,invert,varray()); - ADDFUNC0(ARRAY,BOOL,Array,is_shared,varray()); + ADDFUNC0(POOL_BYTE_ARRAY,INT,PoolByteArray,size,varray()); ADDFUNC2(POOL_BYTE_ARRAY,NIL,PoolByteArray,set,INT,"idx",INT,"byte",varray()); diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 1e67d81ae2..281d2e8192 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -507,7 +507,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& } const Array &array_a=*reinterpret_cast<const Array *>(p_a._data._mem); const Array &array_b=*reinterpret_cast<const Array *>(p_b._data._mem); - Array sum(array_a.is_shared() || array_b.is_shared()); + Array sum; int asize=array_a.size(); int bsize=array_b.size(); sum.resize(asize+bsize); @@ -2949,7 +2949,7 @@ bool Variant::iter_init(Variant& r_iter,bool &valid) const { #endif Variant::CallError ce; ce.error=Variant::CallError::CALL_OK; - Array ref(true); + Array ref; ref.push_back(r_iter); Variant vref=ref; const Variant *refp[]={&vref}; @@ -3075,7 +3075,7 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const { #endif Variant::CallError ce; ce.error=Variant::CallError::CALL_OK; - Array ref(true); + Array ref; ref.push_back(r_iter); Variant vref=ref; const Variant *refp[]={&vref}; |