Skip to content

Commit 58317f0

Browse files
committed
properly perserving string pointers when merging time series
1 parent cd9a114 commit 58317f0

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
@@ -382,7 +382,7 @@ class PlotDataBase
382382
}
383383

384384

385-
void mergeWith(PlotDataBase<TypeX, Value>& other) {
385+
virtual void mergeWith(PlotDataBase<TypeX, Value>& other) {
386386
if (other._points.empty())
387387
return;
388388

@@ -405,17 +405,16 @@ class PlotDataBase
405405
}
406406

407407
if constexpr (std::is_arithmetic_v<TypeX>) {
408+
// new points are all before this->_points
409+
if (other._points.back().x < this->_points.front().x) {
410+
this->_points.swap(other._points);
411+
}
408412

409413
// new points are all after this->_points
410414
if (other._points.front().x > this->_points.back().x) {
411415
std::move(other._points.begin(), other._points.end(), std::back_inserter(this->_points));
412-
413-
// new points are all before this->_points
414-
} else if (other._points.back().x < this->_points.front().x) {
415-
std::move(this->_points.begin(), this->_points.end(), std::back_inserter(other._points));
416-
this->_points.swap(other._points);
417416
} else {
418-
// Fallback to standard merging with move where possible
417+
// Overlap: fallback to standard merging with move where possible
419418
std::deque<Point> result;
420419
std::merge(std::make_move_iterator(this->_points.begin()), std::make_move_iterator(this->_points.end()),
421420
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)