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

@ -286,7 +286,7 @@ void Tabs::_notification(int p_what) {
for (int i = 0; i < tabs.size(); i++) {
tabs[i].ofs_cache = mw;
tabs.write[i].ofs_cache = mw;
mw += get_tab_width(i);
}
@ -314,7 +314,7 @@ void Tabs::_notification(int p_what) {
if (i < offset)
continue;
tabs[i].ofs_cache = w;
tabs.write[i].ofs_cache = w;
int lsize = tabs[i].size_cache;
@ -379,7 +379,7 @@ void Tabs::_notification(int p_what) {
rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.position.y + style->get_margin(MARGIN_TOP)));
w += rb->get_width();
tabs[i].rb_rect = rb_rect;
tabs.write[i].rb_rect = rb_rect;
}
if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
@ -403,7 +403,7 @@ void Tabs::_notification(int p_what) {
cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.position.y + style->get_margin(MARGIN_TOP)));
w += cb->get_width();
tabs[i].cb_rect = cb_rect;
tabs.write[i].cb_rect = cb_rect;
}
w += sb->get_margin(MARGIN_RIGHT);
@ -471,7 +471,7 @@ bool Tabs::get_offset_buttons_visible() const {
void Tabs::set_tab_title(int p_tab, const String &p_title) {
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs[p_tab].text = p_title;
tabs.write[p_tab].text = p_title;
update();
minimum_size_changed();
}
@ -485,7 +485,7 @@ String Tabs::get_tab_title(int p_tab) const {
void Tabs::set_tab_icon(int p_tab, const Ref<Texture> &p_icon) {
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs[p_tab].icon = p_icon;
tabs.write[p_tab].icon = p_icon;
update();
minimum_size_changed();
}
@ -499,7 +499,7 @@ Ref<Texture> Tabs::get_tab_icon(int p_tab) const {
void Tabs::set_tab_disabled(int p_tab, bool p_disabled) {
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs[p_tab].disabled = p_disabled;
tabs.write[p_tab].disabled = p_disabled;
update();
}
bool Tabs::get_tab_disabled(int p_tab) const {
@ -511,7 +511,7 @@ bool Tabs::get_tab_disabled(int p_tab) const {
void Tabs::set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button) {
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs[p_tab].right_button = p_right_button;
tabs.write[p_tab].right_button = p_right_button;
_update_cache();
update();
minimum_size_changed();
@ -536,9 +536,9 @@ void Tabs::_update_cache() {
int size_fixed = 0;
int count_resize = 0;
for (int i = 0; i < tabs.size(); i++) {
tabs[i].ofs_cache = mw;
tabs[i].size_cache = get_tab_width(i);
tabs[i].size_text = font->get_string_size(tabs[i].text).width;
tabs.write[i].ofs_cache = mw;
tabs.write[i].size_cache = get_tab_width(i);
tabs.write[i].size_text = font->get_string_size(tabs[i].text).width;
mw += tabs[i].size_cache;
if (tabs[i].size_cache <= min_width || i == current) {
size_fixed += tabs[i].size_cache;
@ -579,9 +579,9 @@ void Tabs::_update_cache() {
lsize = m_width;
}
}
tabs[i].ofs_cache = w;
tabs[i].size_cache = lsize;
tabs[i].size_text = slen;
tabs.write[i].ofs_cache = w;
tabs.write[i].size_cache = lsize;
tabs.write[i].size_text = slen;
w += lsize;
}
}