Use string_view from simdjson. Interesting speed up.

Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2021-10-24 11:15:10 +01:00
parent 03b536838b
commit f8b5045f99
6 changed files with 20 additions and 19 deletions

View File

@ -42,15 +42,6 @@ void TestRunner::addActualWriteCycle(const EightBit::register16_t address, const
addActualCycle(address, value, "write");
}
void TestRunner::dumpCycle(const uint16_t address, const uint8_t value, const std::string action) {
os()
<< std::setfill('0') << std::hex
<< "Address: " << std::setw(4) << (int)address
<< ", value: " << std::setw(2) << (int)value
<< ", action: " << action;
pushCurrentMessage();
}
void TestRunner::dumpCycles(const std::string which, const actual_cycles_t& events) {
m_messages.push_back(which);
dumpCycles(events);
@ -116,7 +107,7 @@ void TestRunner::raise(const std::string what, const uint8_t expected, const uin
pushCurrentMessage();
}
void TestRunner::raise(const std::string what, const std::string expected, const std::string actual) {
void TestRunner::raise(const std::string what, const std::string_view expected, const std::string_view actual) {
os()
<< std::setw(0) << std::setfill(' ')
<< what
@ -164,7 +155,7 @@ bool TestRunner::checkState() {
const auto actual = actual_cycles.at(actual_idx++); // actual could be less than expected
check("Cycle address", expected.address(), std::get<0>(actual));
check("Cycle value", expected.value(), std::get<1>(actual));
check("Cycle action", expected.action(), std::get<2>(actual));
check("Cycle action", expected.action(), std::string_view(std::get<2>(actual)));
}
const auto final = test().final();

View File

@ -47,7 +47,7 @@ private:
void raise(std::string what, uint16_t expected, uint16_t actual);
void raise(std::string what, uint8_t expected, uint8_t actual);
void raise(std::string what, std::string expected, std::string actual);
void raise(std::string what, std::string_view expected, std::string_view actual);
template<class T>
bool check(std::string what, T expected, T actual) {
@ -68,7 +68,15 @@ private:
void disassemble(uint16_t address);
void dumpCycle(uint16_t address, uint8_t value, std::string action);
template<class T>
void dumpCycle(const uint16_t address, const uint8_t value, const T action) {
os()
<< std::setfill('0') << std::hex
<< "Address: " << std::setw(4) << (int)address
<< ", value: " << std::setw(2) << (int)value
<< ", action: " << action;
pushCurrentMessage();
}
void dumpCycles(std::string which, cycles_t cycles);
void dumpCycles(cycles_t cycles);

View File

@ -14,9 +14,7 @@ protected:
[[nodiscard]] auto raw() const noexcept { return m_raw; }
[[nodiscard]] auto at(size_t idx) const noexcept { return raw().at(idx); }
[[nodiscard]] auto integer_at(size_t idx) const noexcept { return (int64_t)at(idx); }
[[nodiscard]] auto address_at(size_t idx) const noexcept { return (uint16_t)integer_at(idx); }
[[nodiscard]] auto byte_at(size_t idx) const noexcept { return (uint8_t)integer_at(idx); }
[[nodiscard]] auto integer_at(size_t idx) const noexcept { return at(idx).get_int64(); }
public:
[[nodiscard]] auto begin() const noexcept { return m_raw.begin(); }

View File

@ -5,6 +5,10 @@
#include "array_t.h"
class byte_t : public array_t {
protected:
[[nodiscard]] auto address_at(size_t idx) const noexcept { return (uint16_t)integer_at(idx); }
[[nodiscard]] auto byte_at(size_t idx) const noexcept { return (uint8_t)integer_at(idx); }
public:
byte_t(simdjson::dom::array input) noexcept;

View File

@ -10,5 +10,5 @@ class cycle_t final : public byte_t {
public:
cycle_t(simdjson::dom::array input) noexcept;
[[nodiscard]] auto action() const noexcept { return (std::string)at(2); }
[[nodiscard]] std::string_view action() const noexcept { return at(2).get_string(); }
};

View File

@ -12,10 +12,10 @@ private:
protected:
element_t(simdjson::dom::element input) noexcept;
auto raw() const noexcept { return m_raw; }
[[nodiscard]] auto raw() const noexcept { return m_raw; }
[[nodiscard]] auto at(std::string key) const noexcept { return raw()[key]; }
[[nodiscard]] auto operator[](std::string key) const noexcept { return at(key); }
[[nodiscard]] auto array_at(std::string key) const noexcept { return at(key).get_array(); }
[[nodiscard]] auto integer_at(std::string key) const noexcept { return (int64_t)at(key); }
[[nodiscard]] auto integer_at(std::string key) const noexcept { return at(key).get_int64(); }
};