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:
@@ -37,9 +37,9 @@
|
||||
void EditorProfiler::_make_metric_ptrs(Metric &m) {
|
||||
|
||||
for (int i = 0; i < m.categories.size(); i++) {
|
||||
m.category_ptrs[m.categories[i].signature] = &m.categories[i];
|
||||
m.category_ptrs[m.categories[i].signature] = &m.categories.write[i];
|
||||
for (int j = 0; j < m.categories[i].items.size(); j++) {
|
||||
m.item_ptrs[m.categories[i].items[j].signature] = &m.categories[i].items[j];
|
||||
m.item_ptrs[m.categories[i].items[j].signature] = &m.categories.write[i].items.write[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,8 @@ void EditorProfiler::add_frame_metric(const Metric &p_metric, bool p_final) {
|
||||
if (last_metric >= frame_metrics.size())
|
||||
last_metric = 0;
|
||||
|
||||
frame_metrics[last_metric] = p_metric;
|
||||
_make_metric_ptrs(frame_metrics[last_metric]);
|
||||
frame_metrics.write[last_metric] = p_metric;
|
||||
_make_metric_ptrs(frame_metrics.write[last_metric]);
|
||||
|
||||
updating_frame = true;
|
||||
cursor_metric_edit->set_max(frame_metrics[last_metric].frame_number);
|
||||
@@ -108,7 +108,7 @@ static String _get_percent_txt(float p_value, float p_total) {
|
||||
return String::num((p_value / p_total) * 100, 1) + "%";
|
||||
}
|
||||
|
||||
String EditorProfiler::_get_time_as_text(Metric &m, float p_time, int p_calls) {
|
||||
String EditorProfiler::_get_time_as_text(const Metric &m, float p_time, int p_calls) {
|
||||
|
||||
int dmode = display_mode->get_selected();
|
||||
|
||||
@@ -192,18 +192,18 @@ void EditorProfiler::_update_plot() {
|
||||
float highest = 0;
|
||||
|
||||
for (int i = 0; i < frame_metrics.size(); i++) {
|
||||
Metric &m = frame_metrics[i];
|
||||
const Metric &m = frame_metrics[i];
|
||||
if (!m.valid)
|
||||
continue;
|
||||
|
||||
for (Set<StringName>::Element *E = plot_sigs.front(); E; E = E->next()) {
|
||||
|
||||
Map<StringName, Metric::Category *>::Element *F = m.category_ptrs.find(E->get());
|
||||
const Map<StringName, Metric::Category *>::Element *F = m.category_ptrs.find(E->get());
|
||||
if (F) {
|
||||
highest = MAX(F->get()->total_time, highest);
|
||||
}
|
||||
|
||||
Map<StringName, Metric::Category::Item *>::Element *G = m.item_ptrs.find(E->get());
|
||||
const Map<StringName, Metric::Category::Item *>::Element *G = m.item_ptrs.find(E->get());
|
||||
if (G) {
|
||||
if (use_self) {
|
||||
highest = MAX(G->get()->self, highest);
|
||||
@@ -256,18 +256,18 @@ void EditorProfiler::_update_plot() {
|
||||
}
|
||||
|
||||
//get
|
||||
Metric &m = frame_metrics[idx];
|
||||
const Metric &m = frame_metrics[idx];
|
||||
if (m.valid == false)
|
||||
continue; //skip because invalid
|
||||
|
||||
float value = 0;
|
||||
|
||||
Map<StringName, Metric::Category *>::Element *F = m.category_ptrs.find(E->get());
|
||||
const Map<StringName, Metric::Category *>::Element *F = m.category_ptrs.find(E->get());
|
||||
if (F) {
|
||||
value = F->get()->total_time;
|
||||
}
|
||||
|
||||
Map<StringName, Metric::Category::Item *>::Element *G = m.item_ptrs.find(E->get());
|
||||
const Map<StringName, Metric::Category::Item *>::Element *G = m.item_ptrs.find(E->get());
|
||||
if (G) {
|
||||
if (use_self) {
|
||||
value = G->get()->self;
|
||||
@@ -375,7 +375,7 @@ void EditorProfiler::_update_frame() {
|
||||
variables->clear();
|
||||
|
||||
TreeItem *root = variables->create_item();
|
||||
Metric &m = frame_metrics[cursor_metric];
|
||||
const Metric &m = frame_metrics[cursor_metric];
|
||||
|
||||
int dtime = display_time->get_selected();
|
||||
|
||||
@@ -394,7 +394,7 @@ void EditorProfiler::_update_frame() {
|
||||
}
|
||||
|
||||
for (int j = 0; j < m.categories[i].items.size(); j++) {
|
||||
Metric::Category::Item &it = m.categories[i].items[j];
|
||||
const Metric::Category::Item &it = m.categories[i].items[j];
|
||||
|
||||
TreeItem *item = variables->create_item(category);
|
||||
item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
||||
|
||||
Reference in New Issue
Block a user