Skip to content

Commit

Permalink
Merge pull request #20137 from hpvb/reduce-vector-cow
Browse files Browse the repository at this point in the history
Reduce unnecessary COW on Vector by make writing explicit
  • Loading branch information
hpvb authored Jul 25, 2018
2 parents 9423f23 + 0e29f79 commit 832e2bf
Show file tree
Hide file tree
Showing 228 changed files with 2,194 additions and 2,076 deletions.
2 changes: 1 addition & 1 deletion core/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void Array::_unref() const {

Variant &Array::operator[](int p_idx) {

return _p->array[p_idx];
return _p->array.write[p_idx];
}

const Variant &Array::operator[](int p_idx) const {
Expand Down
182 changes: 91 additions & 91 deletions core/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(2);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
return md;
}

Expand All @@ -68,9 +68,9 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(3);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
return md;
}

Expand All @@ -79,10 +79,10 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(4);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
return md;
}

Expand All @@ -91,11 +91,11 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(5);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args[4] = StaticCString::create(p_arg5);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
md.args.write[4] = StaticCString::create(p_arg5);
return md;
}

Expand All @@ -104,12 +104,12 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(6);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args[4] = StaticCString::create(p_arg5);
md.args[5] = StaticCString::create(p_arg6);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
md.args.write[4] = StaticCString::create(p_arg5);
md.args.write[5] = StaticCString::create(p_arg6);
return md;
}

Expand All @@ -118,13 +118,13 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(7);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args[4] = StaticCString::create(p_arg5);
md.args[5] = StaticCString::create(p_arg6);
md.args[6] = StaticCString::create(p_arg7);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
md.args.write[4] = StaticCString::create(p_arg5);
md.args.write[5] = StaticCString::create(p_arg6);
md.args.write[6] = StaticCString::create(p_arg7);
return md;
}

Expand All @@ -133,14 +133,14 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(8);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args[4] = StaticCString::create(p_arg5);
md.args[5] = StaticCString::create(p_arg6);
md.args[6] = StaticCString::create(p_arg7);
md.args[7] = StaticCString::create(p_arg8);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
md.args.write[4] = StaticCString::create(p_arg5);
md.args.write[5] = StaticCString::create(p_arg6);
md.args.write[6] = StaticCString::create(p_arg7);
md.args.write[7] = StaticCString::create(p_arg8);
return md;
}

Expand All @@ -149,15 +149,15 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(9);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args[4] = StaticCString::create(p_arg5);
md.args[5] = StaticCString::create(p_arg6);
md.args[6] = StaticCString::create(p_arg7);
md.args[7] = StaticCString::create(p_arg8);
md.args[8] = StaticCString::create(p_arg9);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
md.args.write[4] = StaticCString::create(p_arg5);
md.args.write[5] = StaticCString::create(p_arg6);
md.args.write[6] = StaticCString::create(p_arg7);
md.args.write[7] = StaticCString::create(p_arg8);
md.args.write[8] = StaticCString::create(p_arg9);
return md;
}

Expand All @@ -166,16 +166,16 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(10);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args[4] = StaticCString::create(p_arg5);
md.args[5] = StaticCString::create(p_arg6);
md.args[6] = StaticCString::create(p_arg7);
md.args[7] = StaticCString::create(p_arg8);
md.args[8] = StaticCString::create(p_arg9);
md.args[9] = StaticCString::create(p_arg10);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
md.args.write[4] = StaticCString::create(p_arg5);
md.args.write[5] = StaticCString::create(p_arg6);
md.args.write[6] = StaticCString::create(p_arg7);
md.args.write[7] = StaticCString::create(p_arg8);
md.args.write[8] = StaticCString::create(p_arg9);
md.args.write[9] = StaticCString::create(p_arg10);
return md;
}

Expand All @@ -184,17 +184,17 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(11);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args[4] = StaticCString::create(p_arg5);
md.args[5] = StaticCString::create(p_arg6);
md.args[6] = StaticCString::create(p_arg7);
md.args[7] = StaticCString::create(p_arg8);
md.args[8] = StaticCString::create(p_arg9);
md.args[9] = StaticCString::create(p_arg10);
md.args[10] = StaticCString::create(p_arg11);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
md.args.write[4] = StaticCString::create(p_arg5);
md.args.write[5] = StaticCString::create(p_arg6);
md.args.write[6] = StaticCString::create(p_arg7);
md.args.write[7] = StaticCString::create(p_arg8);
md.args.write[8] = StaticCString::create(p_arg9);
md.args.write[9] = StaticCString::create(p_arg10);
md.args.write[10] = StaticCString::create(p_arg11);
return md;
}

Expand All @@ -203,18 +203,18 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(12);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args[4] = StaticCString::create(p_arg5);
md.args[5] = StaticCString::create(p_arg6);
md.args[6] = StaticCString::create(p_arg7);
md.args[7] = StaticCString::create(p_arg8);
md.args[8] = StaticCString::create(p_arg9);
md.args[9] = StaticCString::create(p_arg10);
md.args[10] = StaticCString::create(p_arg11);
md.args[11] = StaticCString::create(p_arg12);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
md.args.write[4] = StaticCString::create(p_arg5);
md.args.write[5] = StaticCString::create(p_arg6);
md.args.write[6] = StaticCString::create(p_arg7);
md.args.write[7] = StaticCString::create(p_arg8);
md.args.write[8] = StaticCString::create(p_arg9);
md.args.write[9] = StaticCString::create(p_arg10);
md.args.write[10] = StaticCString::create(p_arg11);
md.args.write[11] = StaticCString::create(p_arg12);
return md;
}

Expand All @@ -223,19 +223,19 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(13);
md.args[0] = StaticCString::create(p_arg1);
md.args[1] = StaticCString::create(p_arg2);
md.args[2] = StaticCString::create(p_arg3);
md.args[3] = StaticCString::create(p_arg4);
md.args[4] = StaticCString::create(p_arg5);
md.args[5] = StaticCString::create(p_arg6);
md.args[6] = StaticCString::create(p_arg7);
md.args[7] = StaticCString::create(p_arg8);
md.args[8] = StaticCString::create(p_arg9);
md.args[9] = StaticCString::create(p_arg10);
md.args[10] = StaticCString::create(p_arg11);
md.args[11] = StaticCString::create(p_arg12);
md.args[12] = StaticCString::create(p_arg13);
md.args.write[0] = StaticCString::create(p_arg1);
md.args.write[1] = StaticCString::create(p_arg2);
md.args.write[2] = StaticCString::create(p_arg3);
md.args.write[3] = StaticCString::create(p_arg4);
md.args.write[4] = StaticCString::create(p_arg5);
md.args.write[5] = StaticCString::create(p_arg6);
md.args.write[6] = StaticCString::create(p_arg7);
md.args.write[7] = StaticCString::create(p_arg8);
md.args.write[8] = StaticCString::create(p_arg9);
md.args.write[9] = StaticCString::create(p_arg10);
md.args.write[10] = StaticCString::create(p_arg11);
md.args.write[11] = StaticCString::create(p_arg12);
md.args.write[12] = StaticCString::create(p_arg13);
return md;
}

Expand Down Expand Up @@ -1246,7 +1246,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c
defvals.resize(p_defcount);
for (int i = 0; i < p_defcount; i++) {

defvals[i] = *p_defs[p_defcount - i - 1];
defvals.write[i] = *p_defs[p_defcount - i - 1];
}

p_bind->set_default_arguments(defvals);
Expand Down
12 changes: 6 additions & 6 deletions core/compressed_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
Pair<int, CharString> p;
p.first = idx;
p.second = cs;
buckets[h % size].push_back(p);
buckets.write[h % size].push_back(p);

//compress string
CharString src_s = p_from->get_message(E->get()).operator String().utf8();
Expand All @@ -100,7 +100,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
ps.compressed[0] = 0;
}

compressed[idx] = ps;
compressed.write[idx] = ps;
total_compression_size += ps.compressed.size();
total_string_size += src_s.size();
idx++;
Expand All @@ -111,8 +111,8 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {

for (int i = 0; i < size; i++) {

Vector<Pair<int, CharString> > &b = buckets[i];
Map<uint32_t, int> &t = table[i];
const Vector<Pair<int, CharString> > &b = buckets[i];
Map<uint32_t, int> &t = table.write[i];

if (b.size() == 0)
continue;
Expand All @@ -136,7 +136,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
}
}

hfunc_table[i] = d;
hfunc_table.write[i] = d;
bucket_table_size += 2 + b.size() * 4;
}

Expand All @@ -157,7 +157,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {

for (int i = 0; i < size; i++) {

Map<uint32_t, int> &t = table[i];
const Map<uint32_t, int> &t = table[i];
if (t.size() == 0) {
htw[i] = 0xFFFFFFFF; //nothing
continue;
Expand Down
Loading

0 comments on commit 832e2bf

Please sign in to comment.