Skip to content

Commit bb04808

Browse files
committed
Upgrade Core to aa314809fdb59ed6fcb1b10b3087f32eebf708c5
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 8b93f69 commit bb04808

334 files changed

Lines changed: 55979 additions & 4103 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DEPENDENCIES

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02
2-
core https://github.com/sourcemeta/core 3ea3a54756071232ca017b96bc15f17d8b5be370
3-
blaze https://github.com/sourcemeta/blaze 0ff98cb5e537f571bdf04f0d59a031a0d8634e07
2+
core https://github.com/sourcemeta/core aa314809fdb59ed6fcb1b10b3087f32eebf708c5
3+
blaze https://github.com/sourcemeta/blaze 5554d3106d7920b28b852e929f0a31d7805effe1
44
bootstrap https://github.com/twbs/bootstrap 1a6fdfae6be09b09eaced8f0e442ca6f7680a61e

src/runtime/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT jsonbinpack NAME runtime
1010
SOURCES
1111
input_stream.cc
1212
output_stream.cc
13-
varint.h
1413
unreachable.h
1514
cache.cc
1615

@@ -44,3 +43,5 @@ target_link_libraries(sourcemeta_jsonbinpack_runtime PUBLIC
4443
sourcemeta::core::json)
4544
target_link_libraries(sourcemeta_jsonbinpack_runtime PUBLIC
4645
sourcemeta::core::numeric)
46+
target_link_libraries(sourcemeta_jsonbinpack_runtime PUBLIC
47+
sourcemeta::core::io)

src/runtime/encoder_string.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ auto Encoder::RFC3339_DATE_INTEGER_TRIPLET(
115115
assert(month >= 1 && month <= 12);
116116
assert(day >= 1 && day <= 31);
117117

118-
this->put_bytes(year);
118+
this->put_word(year);
119119
this->put_byte(month);
120120
this->put_byte(day);
121121
}

src/runtime/include/sourcemeta/jsonbinpack/runtime_input_stream.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,29 @@
55
#include <sourcemeta/jsonbinpack/runtime_export.h>
66
#endif
77

8+
#include <sourcemeta/core/io_binary.h>
89
#include <sourcemeta/core/json.h>
910

10-
#include <cstdint> // std::uint8_t, std::uint16_t, std::uint64_t
11+
#include <cstdint> // std::uint64_t, std::int64_t
1112
#include <istream> // std::basic_istream
1213

1314
namespace sourcemeta::jsonbinpack {
1415

1516
/// @ingroup runtime
16-
class SOURCEMETA_JSONBINPACK_RUNTIME_EXPORT InputStream {
17+
class SOURCEMETA_JSONBINPACK_RUNTIME_EXPORT InputStream
18+
: public sourcemeta::core::BinaryReader {
1719
public:
1820
using Stream = std::basic_istream<sourcemeta::core::JSON::Char,
1921
sourcemeta::core::JSON::CharTraits>;
2022
InputStream(Stream &input);
21-
// Prevent copying, as this class is tied to a stream resource
22-
InputStream(const InputStream &) = delete;
23-
auto operator=(const InputStream &) -> InputStream & = delete;
2423

25-
[[nodiscard]] auto position() const noexcept -> std::uint64_t;
26-
auto seek(const std::uint64_t offset) -> void;
2724
// Seek backwards given a relative offset
2825
auto rewind(const std::uint64_t relative_offset, const std::uint64_t position)
2926
-> std::uint64_t;
30-
auto get_byte() -> std::uint8_t;
31-
// A "word" corresponds to two bytes
32-
// See https://stackoverflow.com/questions/28066462/how-many-bits-is-a-word
33-
auto get_word() -> std::uint16_t;
3427
auto get_varint() -> std::uint64_t;
3528
auto get_varint_zigzag() -> std::int64_t;
36-
[[nodiscard]] auto has_more_data() const noexcept -> bool;
3729
auto get_string_utf8(const std::uint64_t length)
3830
-> sourcemeta::core::JSON::String;
39-
40-
private:
41-
Stream &stream;
4231
};
4332

4433
} // namespace sourcemeta::jsonbinpack

src/runtime/include/sourcemeta/jsonbinpack/runtime_output_stream.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,26 @@
55
#include <sourcemeta/jsonbinpack/runtime_export.h>
66
#endif
77

8+
#include <sourcemeta/core/io_binary.h>
89
#include <sourcemeta/core/json.h>
910

10-
#include <cstdint> // std::uint8_t, std::uint16_t, std::uint64_t
11+
#include <cstdint> // std::uint64_t, std::int64_t
1112
#include <ostream> // std::basic_ostream
1213

1314
namespace sourcemeta::jsonbinpack {
1415

1516
/// @ingroup runtime
16-
class SOURCEMETA_JSONBINPACK_RUNTIME_EXPORT OutputStream {
17+
class SOURCEMETA_JSONBINPACK_RUNTIME_EXPORT OutputStream
18+
: public sourcemeta::core::BinaryWriter {
1719
public:
1820
using Stream = std::basic_ostream<sourcemeta::core::JSON::Char,
1921
sourcemeta::core::JSON::CharTraits>;
2022
OutputStream(Stream &output);
2123

22-
// Prevent copying, as this class is tied to a stream resource
23-
OutputStream(const OutputStream &) = delete;
24-
auto operator=(const OutputStream &) -> OutputStream & = delete;
25-
26-
[[nodiscard]] auto position() const noexcept -> std::uint64_t;
27-
auto put_byte(const std::uint8_t byte) -> void;
28-
auto put_bytes(const std::uint16_t bytes) -> void;
2924
auto put_varint(const std::uint64_t value) -> void;
3025
auto put_varint_zigzag(const std::int64_t value) -> void;
3126
auto put_string_utf8(const sourcemeta::core::JSON::String &string,
3227
const std::uint64_t length) -> void;
33-
34-
private:
35-
Stream &stream;
3628
};
3729

3830
} // namespace sourcemeta::jsonbinpack

src/runtime/input_stream.cc

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@
22

33
#include <sourcemeta/core/numeric.h>
44

5-
#include "varint.h"
6-
75
#include <cassert> // assert
8-
#include <ios> // std::ios_base
6+
#include <cstddef> // std::size_t
7+
#include <cstdint> // std::uint8_t, std::uint64_t, std::int64_t
98

109
namespace sourcemeta::jsonbinpack {
1110

12-
InputStream::InputStream(Stream &input) : stream{input} {
13-
this->stream.exceptions(std::ios_base::badbit | std::ios_base::failbit |
14-
std::ios_base::eofbit);
15-
}
16-
17-
auto InputStream::position() const noexcept -> std::uint64_t {
18-
return static_cast<std::uint64_t>(this->stream.tellg());
19-
}
20-
21-
auto InputStream::seek(const std::uint64_t offset) -> void {
22-
this->stream.seekg(static_cast<std::streamoff>(offset));
23-
}
11+
InputStream::InputStream(Stream &input)
12+
: sourcemeta::core::BinaryReader{input} {}
2413

2514
auto InputStream::rewind(const std::uint64_t relative_offset,
2615
const std::uint64_t position) -> std::uint64_t {
@@ -32,33 +21,33 @@ auto InputStream::rewind(const std::uint64_t relative_offset,
3221
return current;
3322
}
3423

35-
auto InputStream::get_byte() -> std::uint8_t {
36-
return static_cast<std::uint8_t>(this->stream.get());
37-
}
38-
39-
auto InputStream::get_word() -> std::uint16_t {
40-
std::uint16_t word;
41-
this->stream.read(reinterpret_cast<char *>(&word), sizeof word);
42-
return word;
43-
}
44-
4524
auto InputStream::get_varint() -> std::uint64_t {
46-
return varint_decode(this->stream);
47-
}
25+
constexpr std::uint8_t LEAST_SIGNIFICANT_BITS{0b01111111};
26+
constexpr std::uint8_t MOST_SIGNIFICANT_BIT{0b10000000};
27+
constexpr std::uint8_t SHIFT{7};
28+
std::uint64_t result{0};
29+
std::size_t cursor{0};
30+
while (true) {
31+
const std::uint8_t byte{this->get_byte()};
32+
const std::uint64_t value{
33+
static_cast<std::uint64_t>(byte & LEAST_SIGNIFICANT_BITS)};
34+
#ifndef NDEBUG
35+
const std::uint64_t current = result;
36+
#endif
37+
result += static_cast<std::uint64_t>(value << SHIFT * cursor);
38+
// Try to catch potential overflows from the above addition
39+
assert(result >= current);
40+
cursor += 1;
41+
if ((byte & MOST_SIGNIFICANT_BIT) == 0) {
42+
break;
43+
}
44+
}
4845

49-
auto InputStream::get_varint_zigzag() -> std::int64_t {
50-
const std::uint64_t value = varint_decode(this->stream);
51-
return sourcemeta::core::zigzag_decode(value);
46+
return result;
5247
}
5348

54-
auto InputStream::has_more_data() const noexcept -> bool {
55-
// A way to check if the stream is empty without using `.peek()`,
56-
// which throws given we set exceptions on the EOF bit.
57-
// However, `in_avail()` works on characters and will return zero
58-
// if all that's remaining is 0x00 (null), so we need to handle
59-
// that case separately.
60-
return this->stream.rdbuf()->in_avail() > 0 ||
61-
this->stream.rdbuf()->sgetc() == '\0';
49+
auto InputStream::get_varint_zigzag() -> std::int64_t {
50+
return sourcemeta::core::zigzag_decode(this->get_varint());
6251
}
6352

6453
auto InputStream::get_string_utf8(const std::uint64_t length)

src/runtime/output_stream.cc

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,31 @@
22

33
#include <sourcemeta/core/numeric.h>
44

5-
#include "varint.h"
6-
75
#include <cassert> // assert
8-
#include <ios> // std::ios_base
6+
#include <cstdint> // std::uint8_t, std::uint64_t, std::int64_t
97

108
namespace sourcemeta::jsonbinpack {
119

12-
OutputStream::OutputStream(Stream &output) : stream{output} {
13-
this->stream.exceptions(std::ios_base::badbit | std::ios_base::failbit |
14-
std::ios_base::eofbit);
15-
}
16-
17-
auto OutputStream::position() const noexcept -> std::uint64_t {
18-
return static_cast<std::uint64_t>(this->stream.tellp());
19-
}
20-
21-
auto OutputStream::put_byte(const std::uint8_t byte) -> void {
22-
this->stream.put(static_cast<sourcemeta::core::JSON::Char>(byte));
23-
}
24-
25-
auto OutputStream::put_bytes(const std::uint16_t bytes) -> void {
26-
this->stream.write(
27-
reinterpret_cast<const sourcemeta::core::JSON::Char *>(&bytes),
28-
sizeof bytes);
29-
}
10+
OutputStream::OutputStream(Stream &output)
11+
: sourcemeta::core::BinaryWriter{output} {}
3012

3113
auto OutputStream::put_varint(const std::uint64_t value) -> void {
32-
varint_encode(this->stream, value);
14+
constexpr std::uint8_t LEAST_SIGNIFICANT_BITS{0b01111111};
15+
constexpr std::uint8_t MOST_SIGNIFICANT_BIT{0b10000000};
16+
constexpr std::uint8_t SHIFT{7};
17+
std::uint64_t accumulator = value;
18+
19+
while (accumulator > LEAST_SIGNIFICANT_BITS) {
20+
this->put_byte(static_cast<std::uint8_t>(
21+
(accumulator & LEAST_SIGNIFICANT_BITS) | MOST_SIGNIFICANT_BIT));
22+
accumulator >>= SHIFT;
23+
}
24+
25+
this->put_byte(static_cast<std::uint8_t>(accumulator));
3326
}
3427

3528
auto OutputStream::put_varint_zigzag(const std::int64_t value) -> void {
36-
varint_encode(this->stream, sourcemeta::core::zigzag_encode(value));
29+
this->put_varint(sourcemeta::core::zigzag_encode(value));
3730
}
3831

3932
auto OutputStream::put_string_utf8(const sourcemeta::core::JSON::String &string,

src/runtime/varint.h

Lines changed: 0 additions & 60 deletions
This file was deleted.

vendor/blaze/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/blaze/DEPENDENCIES

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)