MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / AppendToVector

Function AppendToVector

source/util/string_utils.h:51–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49// to an existing vector.
50template <class VectorType = std::vector<uint32_t>>
51inline void AppendToVector(const std::string& input, VectorType* result) {
52 static_assert(std::is_same<uint32_t, typename VectorType::value_type>::value);
53 uint32_t word = 0;
54 size_t num_bytes = input.size();
55 // SPIR-V strings are null-terminated. The byte_index == num_bytes
56 // case is used to push the terminating null byte.
57 for (size_t byte_index = 0; byte_index <= num_bytes; byte_index++) {
58 const auto new_byte =
59 (byte_index < num_bytes ? uint8_t(input[byte_index]) : uint8_t(0));
60 word |= (new_byte << (8 * (byte_index % sizeof(uint32_t))));
61 if (3 == (byte_index % sizeof(uint32_t))) {
62 result->push_back(word);
63 word = 0;
64 }
65 }
66 // Emit a trailing partial word.
67 if ((num_bytes + 1) % sizeof(uint32_t)) {
68 result->push_back(word);
69 }
70}
71
72// Encodes a string as a sequence of words, using the SPIR-V encoding.
73template <class VectorType = std::vector<uint32_t>>

Callers 3

binaryEncodeStringMethod · 0.85
MakeVectorFunction · 0.85

Calls 2

sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected