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:
@ -410,7 +410,7 @@ void PopupMenu::_notification(int p_what) {
|
||||
case NOTIFICATION_TRANSLATION_CHANGED: {
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
items[i].xl_text = tr(items[i].text);
|
||||
items.write[i].xl_text = tr(items[i].text);
|
||||
}
|
||||
|
||||
minimum_size_changed();
|
||||
@ -524,7 +524,7 @@ void PopupMenu::_notification(int p_what) {
|
||||
font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, i == mouse_over ? font_color_hover : font_color_accel);
|
||||
}
|
||||
|
||||
items[i]._ofs_cache = ofs.y;
|
||||
items.write[i]._ofs_cache = ofs.y;
|
||||
|
||||
ofs.y += h;
|
||||
}
|
||||
@ -622,7 +622,7 @@ void PopupMenu::add_check_item(const String &p_label, int p_ID, uint32_t p_accel
|
||||
void PopupMenu::add_radio_check_item(const String &p_label, int p_ID, uint32_t p_accel) {
|
||||
|
||||
add_check_item(p_label, p_ID, p_accel);
|
||||
items[items.size() - 1].checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON;
|
||||
items.write[items.size() - 1].checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
@ -630,7 +630,7 @@ void PopupMenu::add_radio_check_item(const String &p_label, int p_ID, uint32_t p
|
||||
void PopupMenu::add_icon_radio_check_item(const Ref<Texture> &p_icon, const String &p_label, int p_ID, uint32_t p_accel) {
|
||||
|
||||
add_icon_check_item(p_icon, p_label, p_ID, p_accel);
|
||||
items[items.size() - 1].checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON;
|
||||
items.write[items.size() - 1].checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
@ -702,7 +702,7 @@ void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_ID, bo
|
||||
void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_ID, bool p_global) {
|
||||
|
||||
add_check_shortcut(p_shortcut, p_ID, p_global);
|
||||
items[items.size() - 1].checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON;
|
||||
items.write[items.size() - 1].checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
@ -724,8 +724,8 @@ void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int
|
||||
void PopupMenu::set_item_text(int p_idx, const String &p_text) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].text = p_text;
|
||||
items[p_idx].xl_text = tr(p_text);
|
||||
items.write[p_idx].text = p_text;
|
||||
items.write[p_idx].xl_text = tr(p_text);
|
||||
|
||||
update();
|
||||
minimum_size_changed();
|
||||
@ -733,7 +733,7 @@ void PopupMenu::set_item_text(int p_idx, const String &p_text) {
|
||||
void PopupMenu::set_item_icon(int p_idx, const Ref<Texture> &p_icon) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].icon = p_icon;
|
||||
items.write[p_idx].icon = p_icon;
|
||||
|
||||
update();
|
||||
minimum_size_changed();
|
||||
@ -742,7 +742,7 @@ void PopupMenu::set_item_checked(int p_idx, bool p_checked) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
|
||||
items[p_idx].checked = p_checked;
|
||||
items.write[p_idx].checked = p_checked;
|
||||
|
||||
update();
|
||||
minimum_size_changed();
|
||||
@ -750,7 +750,7 @@ void PopupMenu::set_item_checked(int p_idx, bool p_checked) {
|
||||
void PopupMenu::set_item_id(int p_idx, int p_ID) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].ID = p_ID;
|
||||
items.write[p_idx].ID = p_ID;
|
||||
|
||||
update();
|
||||
minimum_size_changed();
|
||||
@ -759,7 +759,7 @@ void PopupMenu::set_item_id(int p_idx, int p_ID) {
|
||||
void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].accel = p_accel;
|
||||
items.write[p_idx].accel = p_accel;
|
||||
|
||||
update();
|
||||
minimum_size_changed();
|
||||
@ -768,7 +768,7 @@ void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) {
|
||||
void PopupMenu::set_item_metadata(int p_idx, const Variant &p_meta) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].metadata = p_meta;
|
||||
items.write[p_idx].metadata = p_meta;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
@ -776,7 +776,7 @@ void PopupMenu::set_item_metadata(int p_idx, const Variant &p_meta) {
|
||||
void PopupMenu::set_item_disabled(int p_idx, bool p_disabled) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].disabled = p_disabled;
|
||||
items.write[p_idx].disabled = p_disabled;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
@ -784,7 +784,7 @@ void PopupMenu::set_item_disabled(int p_idx, bool p_disabled) {
|
||||
void PopupMenu::set_item_submenu(int p_idx, const String &p_submenu) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].submenu = p_submenu;
|
||||
items.write[p_idx].submenu = p_submenu;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
@ -792,7 +792,7 @@ void PopupMenu::set_item_submenu(int p_idx, const String &p_submenu) {
|
||||
void PopupMenu::toggle_item_checked(int p_idx) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].checked = !items[p_idx].checked;
|
||||
items.write[p_idx].checked = !items[p_idx].checked;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
@ -886,7 +886,7 @@ int PopupMenu::get_item_state(int p_idx) const {
|
||||
void PopupMenu::set_item_as_separator(int p_idx, bool p_separator) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].separator = p_separator;
|
||||
items.write[p_idx].separator = p_separator;
|
||||
update();
|
||||
}
|
||||
|
||||
@ -898,21 +898,21 @@ bool PopupMenu::is_item_separator(int p_idx) const {
|
||||
void PopupMenu::set_item_as_checkable(int p_idx, bool p_checkable) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].checkable_type = p_checkable ? Item::CHECKABLE_TYPE_CHECK_BOX : Item::CHECKABLE_TYPE_NONE;
|
||||
items.write[p_idx].checkable_type = p_checkable ? Item::CHECKABLE_TYPE_CHECK_BOX : Item::CHECKABLE_TYPE_NONE;
|
||||
update();
|
||||
}
|
||||
|
||||
void PopupMenu::set_item_as_radio_checkable(int p_idx, bool p_radio_checkable) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].checkable_type = p_radio_checkable ? Item::CHECKABLE_TYPE_RADIO_BUTTON : Item::CHECKABLE_TYPE_NONE;
|
||||
items.write[p_idx].checkable_type = p_radio_checkable ? Item::CHECKABLE_TYPE_RADIO_BUTTON : Item::CHECKABLE_TYPE_NONE;
|
||||
update();
|
||||
}
|
||||
|
||||
void PopupMenu::set_item_tooltip(int p_idx, const String &p_tooltip) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].tooltip = p_tooltip;
|
||||
items.write[p_idx].tooltip = p_tooltip;
|
||||
update();
|
||||
}
|
||||
|
||||
@ -921,8 +921,8 @@ void PopupMenu::set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut, bo
|
||||
if (items[p_idx].shortcut.is_valid()) {
|
||||
_unref_shortcut(items[p_idx].shortcut);
|
||||
}
|
||||
items[p_idx].shortcut = p_shortcut;
|
||||
items[p_idx].shortcut_is_global = p_global;
|
||||
items.write[p_idx].shortcut = p_shortcut;
|
||||
items.write[p_idx].shortcut_is_global = p_global;
|
||||
|
||||
if (items[p_idx].shortcut.is_valid()) {
|
||||
_ref_shortcut(items[p_idx].shortcut);
|
||||
@ -934,7 +934,7 @@ void PopupMenu::set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut, bo
|
||||
void PopupMenu::set_item_h_offset(int p_idx, int p_offset) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].h_ofs = p_offset;
|
||||
items.write[p_idx].h_ofs = p_offset;
|
||||
update();
|
||||
minimum_size_changed();
|
||||
}
|
||||
@ -942,14 +942,14 @@ void PopupMenu::set_item_h_offset(int p_idx, int p_offset) {
|
||||
void PopupMenu::set_item_multistate(int p_idx, int p_state) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].state = p_state;
|
||||
items.write[p_idx].state = p_state;
|
||||
update();
|
||||
}
|
||||
|
||||
void PopupMenu::set_item_shortcut_disabled(int p_idx, bool p_disabled) {
|
||||
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
items[p_idx].shortcut_is_disabled = p_disabled;
|
||||
items.write[p_idx].shortcut_is_disabled = p_disabled;
|
||||
update();
|
||||
}
|
||||
|
||||
@ -960,9 +960,9 @@ void PopupMenu::toggle_item_multistate(int p_idx) {
|
||||
return;
|
||||
}
|
||||
|
||||
++items[p_idx].state;
|
||||
if (items[p_idx].max_states <= items[p_idx].state)
|
||||
items[p_idx].state = 0;
|
||||
++items.write[p_idx].state;
|
||||
if (items.write[p_idx].max_states <= items[p_idx].state)
|
||||
items.write[p_idx].state = 0;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user