Reduce unnecessary COW on Vector by make writing explicit

This commit makes operator[] on Vector const and adds a write proxy to it.  From
now on writes to Vectors need to happen through the .write proxy. So for
instance:

Vector<int> vec;
vec.push_back(10);
std::cout << vec[0] << std::endl;
vec.write[0] = 20;

Failing to use the .write proxy will cause a compilation error.

In addition COWable datatypes can now embed a CowData pointer to their data.
This means that String, CharString, and VMap no longer use or derive from
Vector.

_ALWAYS_INLINE_ and _FORCE_INLINE_ are now equivalent for debug and non-debug
builds. This is a lot faster for Vector in the editor and while running tests.
The reason why this difference used to exist is because force-inlined methods
used to give a bad debugging experience. After extensive testing with modern
compilers this is no longer the case.
This commit is contained in:
Hein-Pieter van Braam
2018-07-25 03:11:03 +02:00
parent 9423f23ffb
commit 0e29f7974b
228 changed files with 2200 additions and 2082 deletions

View File

@ -113,7 +113,7 @@ void Polygon2D::_notification(int p_what) {
PoolVector<Vector2>::Read polyr = polygon.read();
for (int i = 0; i < len; i++) {
points[i] = polyr[i] + offset;
points.write[i] = polyr[i] + offset;
}
}
@ -153,18 +153,18 @@ void Polygon2D::_notification(int p_what) {
SWAP(ep[1], ep[4]);
SWAP(ep[2], ep[3]);
SWAP(ep[5], ep[0]);
SWAP(ep[6], points[highest_idx]);
SWAP(ep[6], points.write[highest_idx]);
}
points.resize(points.size() + 7);
for (int i = points.size() - 1; i >= highest_idx + 7; i--) {
points[i] = points[i - 7];
points.write[i] = points[i - 7];
}
for (int i = 0; i < 7; i++) {
points[highest_idx + i + 1] = ep[i];
points.write[highest_idx + i + 1] = ep[i];
}
len = points.size();
@ -182,12 +182,12 @@ void Polygon2D::_notification(int p_what) {
PoolVector<Vector2>::Read uvr = uv.read();
for (int i = 0; i < len; i++) {
uvs[i] = texmat.xform(uvr[i]) / tex_size;
uvs.write[i] = texmat.xform(uvr[i]) / tex_size;
}
} else {
for (int i = 0; i < len; i++) {
uvs[i] = texmat.xform(points[i]) / tex_size;
uvs.write[i] = texmat.xform(points[i]) / tex_size;
}
}
}
@ -262,10 +262,10 @@ void Polygon2D::_notification(int p_what) {
{
PoolVector<Color>::Read color_r = vertex_colors.read();
for (int i = 0; i < color_len && i < len; i++) {
colors[i] = color_r[i];
colors.write[i] = color_r[i];
}
for (int i = color_len; i < len; i++) {
colors[i] = color;
colors.write[i] = color;
}
}
@ -333,13 +333,13 @@ void Polygon2D::_notification(int p_what) {
Vector<Vector2> vertices;
vertices.resize(loop.size());
for (int j = 0; j < vertices.size(); j++) {
vertices[j] = points[loop[j]];
vertices.write[j] = points[loop[j]];
}
Vector<int> sub_indices = Geometry::triangulate_polygon(vertices);
int from = indices.size();
indices.resize(from + sub_indices.size());
for (int j = 0; j < sub_indices.size(); j++) {
indices[from + j] = loop[sub_indices[j]];
indices.write[from + j] = loop[sub_indices[j]];
}
}
@ -538,12 +538,12 @@ void Polygon2D::clear_bones() {
void Polygon2D::set_bone_weights(int p_index, const PoolVector<float> &p_weights) {
ERR_FAIL_INDEX(p_index, bone_weights.size());
bone_weights[p_index].weights = p_weights;
bone_weights.write[p_index].weights = p_weights;
update();
}
void Polygon2D::set_bone_path(int p_index, const NodePath &p_path) {
ERR_FAIL_INDEX(p_index, bone_weights.size());
bone_weights[p_index].path = p_path;
bone_weights.write[p_index].path = p_path;
update();
}