1) Remove some try..catch clauses that can easily be handled by if (...) instead
so that debugging unwanted exceptions is easier
2) Replace some iterator-based loops by loops using index-based container access
3) Replace the binary chunk container by a deque
int64_t result = 0;
- try {
- const DecodeSegment *segment = &(segments_.at(segment_id));
- if (include_processing)
- result = segment->samples_decoded_incl;
- else
- result = segment->samples_decoded_excl;
- } catch (out_of_range&) {
- // Do nothing
- }
+ if (segment_id >= segments_.size())
+ return result;
+
+ if (include_processing)
+ result = segments_[segment_id].samples_decoded_incl;
+ else
+ result = segments_[segment_id].samples_decoded_excl;
return result;
}
{
lock_guard<mutex> lock(output_mutex_);
- try {
- const DecodeSegment *segment = &(segments_.at(segment_id));
- const map<const decode::Row, decode::RowData> *rows =
- &(segment->annotation_rows);
+ if (segment_id >= segments_.size())
+ return;
- const auto iter = rows->find(row);
- if (iter != rows->end())
- (*iter).second.get_annotation_subset(dest,
- start_sample, end_sample);
- } catch (out_of_range&) {
- // Do nothing
- }
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+ const map<const decode::Row, decode::RowData> *rows =
+ &(segment->annotation_rows);
+
+ const auto iter = rows->find(row);
+ if (iter != rows->end())
+ (*iter).second.get_annotation_subset(dest, start_sample, end_sample);
}
void DecodeSignal::get_annotation_subset(
uint32_t DecodeSignal::get_binary_data_chunk_count(uint32_t segment_id,
const Decoder* dec, uint32_t bin_class_id) const
{
+ if (segments_.size() == 0)
+ return 0;
+
try {
const DecodeSegment *segment = &(segments_.at(segment_id));
for (uint32_t i = 0; i < n; i++)
segments_.back().binary_classes.push_back(
- {dec.get(), dec->get_binary_class(i), vector<DecodeBinaryDataChunk>()});
+ {dec.get(), dec->get_binary_class(i), deque<DecodeBinaryDataChunk>()});
}
}
#define PULSEVIEW_PV_DATA_DECODESIGNAL_HPP
#include <atomic>
+#include <deque>
#include <condition_variable>
#include <unordered_set>
#include <vector>
using std::atomic;
using std::condition_variable;
+using std::deque;
using std::map;
using std::mutex;
using std::pair;
{
const decode::Decoder* decoder;
const decode::DecodeBinaryClassInfo* info;
- vector<DecodeBinaryDataChunk> chunks;
+ deque<DecodeBinaryDataChunk> chunks;
};
struct DecodeSegment
#include <QApplication>
#include <QClipboard>
+#include <QDebug>
#include <QFont>
#include <QKeyEvent>
#include <QScrollBar>
{
data_ = data;
- data_size_ = 0;
- for (const DecodeBinaryDataChunk& chunk : data_->chunks)
- data_size_ += chunk.data.size();
+ size_t size = 0;
+ size_t chunks = data_->chunks.size();
+ for (size_t i = 0; i < chunks; i++)
+ size += data_->chunks[i].data.size();
+ data_size_ = size;
viewport()->update();
}
current_chunk_offset_ = 0;
current_offset_ = offset;
- for (const DecodeBinaryDataChunk& chunk : data_->chunks)
- if (offset >= chunk.data.size()) {
+ size_t chunks = data_->chunks.size();
+ for (size_t i = 0; i < chunks; i++) {
+ size_t size = data_->chunks[i].data.size();
+
+ if (offset >= size) {
current_chunk_id_++;
- offset -= chunk.data.size();
+ offset -= size;
} else {
current_chunk_offset_ = offset;
break;
}
+ }
- current_chunk_ = data_->chunks[current_chunk_id_];
+ if (current_chunk_id_ < data_->chunks.size())
+ current_chunk_ = data_->chunks[current_chunk_id_];
}
uint8_t QHexView::get_next_byte(bool* is_next_chunk)
if (is_next_chunk != nullptr)
*is_next_chunk = (current_chunk_offset_ == 0);
- uint8_t v = current_chunk_.data[current_chunk_offset_];
+ uint8_t v = 0;
+ if (current_chunk_offset_ < current_chunk_.data.size())
+ v = current_chunk_.data[current_chunk_offset_];
current_offset_++;
current_chunk_offset_++;
- if (current_chunk_offset_ == current_chunk_.data.size()) {
+ if (current_offset_ > data_size_) {
+ qWarning() << "QHexView::get_next_byte() overran binary data boundary:" <<
+ current_offset_ << "of" << data_size_ << "bytes";
+ return 0xEE;
+ }
+
+ if ((current_chunk_offset_ == current_chunk_.data.size()) && (current_offset_ < data_size_)) {
current_chunk_id_++;
current_chunk_offset_ = 0;
current_chunk_ = data_->chunks[current_chunk_id_];
if (hp.x() <= 0) {
value_at_hover_pos_ = std::numeric_limits<float>::quiet_NaN();
} else {
- try {
+ if ((size_t)hp.x() < value_at_pixel_pos_.size())
value_at_hover_pos_ = value_at_pixel_pos_.at(hp.x());
- } catch (out_of_range&) {
+ else
value_at_hover_pos_ = std::numeric_limits<float>::quiet_NaN();
- }
}
}
for (const Row& row : rows) {
// Cache the row title widths
int row_title_width;
- try {
- row_title_width = row_title_widths_.at(row);
- } catch (out_of_range&) {
+ auto cached_width = row_title_widths_.find(row);
+
+ if (cached_width != row_title_widths_.end())
+ row_title_width = cached_width->second;
+ else {
const int w = p.boundingRect(QRectF(), 0, row.title()).width() +
RowTitleMargin;
row_title_widths_[row] = w;