Skip to content

Commit 2fc2d6d

Browse files
committed
properly perserving string pointers when merging time series
1 parent da9aa0a commit 2fc2d6d

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

plotjuggler_base/include/PlotJuggler/plotdatabase.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class PlotDataBase
373373
}
374374

375375

376-
void mergeWith(PlotDataBase<TypeX, Value>& other) {
376+
virtual void mergeWith(PlotDataBase<TypeX, Value>& other) {
377377
if (other._points.empty())
378378
return;
379379

@@ -396,17 +396,16 @@ class PlotDataBase
396396
}
397397

398398
if constexpr (std::is_arithmetic_v<TypeX>) {
399+
// new points are all before this->_points
400+
if (other._points.back().x < this->_points.front().x) {
401+
this->_points.swap(other._points);
402+
}
399403

400404
// new points are all after this->_points
401405
if (other._points.front().x > this->_points.back().x) {
402406
std::move(other._points.begin(), other._points.end(), std::back_inserter(this->_points));
403-
404-
// new points are all before this->_points
405-
} else if (other._points.back().x < this->_points.front().x) {
406-
std::move(this->_points.begin(), this->_points.end(), std::back_inserter(other._points));
407-
this->_points.swap(other._points);
408407
} else {
409-
// Fallback to standard merging with move where possible
408+
// Overlap: fallback to standard merging with move where possible
410409
std::deque<Point> result;
411410
std::merge(std::make_move_iterator(this->_points.begin()), std::make_move_iterator(this->_points.end()),
412411
std::make_move_iterator(other._points.begin()), std::make_move_iterator(other._points.end()),

plotjuggler_base/include/PlotJuggler/stringseries.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ class StringSeries : public TimeseriesBase<StringRef>
7070
}
7171
}
7272

73+
virtual void mergeWith(PlotDataBase<double, StringRef>& other) override {
74+
StringSeries* otherStringSeries = dynamic_cast<StringSeries*>(&other);
75+
if (otherStringSeries) {
76+
for (auto& pointRef : other) {
77+
if (pointRef.y.isSSO()){
78+
continue;
79+
}
80+
81+
_tmp_str.assign(pointRef.y.data(), pointRef.y.size());
82+
83+
auto it = _storage.find(_tmp_str);
84+
if (it == _storage.end())
85+
{
86+
it = _storage.insert(_tmp_str).first;
87+
}
88+
89+
pointRef.y = std::move(StringRef(*it)); // point pointers to this here storage
90+
}
91+
}
92+
PlotDataBase<double, StringRef>::mergeWith(other);
93+
}
94+
7395
private:
7496
std::string _tmp_str;
7597
std::unordered_set<std::string> _storage;

0 commit comments

Comments
 (0)