Tests are passing.

pull/13171/head
Joshua Haberman 3 years ago
parent 4498c88bc0
commit 8ede0d552d
  1. 22
      BUILD
  2. 6
      cmake/CMakeLists.txt
  3. 6
      upb/encode.c
  4. 12
      upb/mini_table.c
  5. 15
      upb/msg_internal.h

22
BUILD

@ -109,6 +109,28 @@ cc_library(
], ],
) )
cc_library(
name = "mini_table",
srcs = ["upb/mini_table.c"],
hdrs = [
"upb/mini_table.h",
"upb/mini_table.hpp",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [":upb"],
)
cc_test(
name = "mini_table_test",
srcs = ["upb/mini_table_test.cc"],
deps = [
":mini_table",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/container:flat_hash_set",
],
)
cc_library( cc_library(
name = "fastdecode", name = "fastdecode",
srcs = [ srcs = [

@ -81,6 +81,12 @@ target_link_libraries(upb
fastdecode fastdecode
port port
/third_party/utf8_range) /third_party/utf8_range)
add_library(mini_table
../upb/mini_table.c
../upb/mini_table.h
../upb/mini_table.hpp)
target_link_libraries(mini_table
upb)
add_library(fastdecode add_library(fastdecode
../upb/decode.h ../upb/decode.h
../upb/decode_fast.c ../upb/decode_fast.c

@ -448,11 +448,17 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg,
memcpy(&ch, mem, 1); memcpy(&ch, mem, 1);
return ch != 0; return ch != 0;
} }
#if UINTPTR_MAX == 0xffffffff
case upb_FieldRep_Pointer:
#endif
case kUpb_FieldRep_4Byte: { case kUpb_FieldRep_4Byte: {
uint32_t u32; uint32_t u32;
memcpy(&u32, mem, 4); memcpy(&u32, mem, 4);
return u32 != 0; return u32 != 0;
} }
#if UINTPTR_MAX != 0xffffffff
case kUpb_FieldRep_Pointer:
#endif
case kUpb_FieldRep_8Byte: { case kUpb_FieldRep_8Byte: {
uint64_t u64; uint64_t u64;
memcpy(&u64, mem, 8); memcpy(&u64, mem, 8);

@ -418,9 +418,9 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch,
static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, uint32_t mod, static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, uint32_t mod,
upb_MiniTable_Field* field) { upb_MiniTable_Field* field) {
if (mod & kUpb_EncodedFieldModifier_IsUnpacked) { if (mod & kUpb_EncodedFieldModifier_IsUnpacked) {
field->mode &= ~upb_LabelFlags_IsPacked; field->mode &= ~kUpb_LabelFlags_IsPacked;
} else { } else {
field->mode |= upb_LabelFlags_IsPacked; field->mode |= kUpb_LabelFlags_IsPacked;
} }
bool singular = mod & kUpb_EncodedFieldModifier_IsProto3Singular; bool singular = mod & kUpb_EncodedFieldModifier_IsProto3Singular;
@ -802,7 +802,7 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len,
decoder.table->size = 0; decoder.table->size = 0;
decoder.table->field_count = 0; decoder.table->field_count = 0;
decoder.table->ext = upb_ExtMode_NonExtendable; decoder.table->ext = kUpb_ExtMode_NonExtendable;
decoder.table->dense_below = 0; decoder.table->dense_below = 0;
decoder.table->table_mask = 0; decoder.table->table_mask = 0;
decoder.table->required_count = 0; decoder.table->required_count = 0;
@ -825,7 +825,7 @@ upb_MiniTable* upb_MiniTable_BuildMessageSet(upb_MiniTablePlatform platform,
ret->size = 0; ret->size = 0;
ret->field_count = 0; ret->field_count = 0;
ret->ext = upb_ExtMode_IsMessageSet; ret->ext = kUpb_ExtMode_IsMessageSet;
ret->dense_below = 0; ret->dense_below = 0;
ret->table_mask = 0; ret->table_mask = 0;
ret->required_count = 0; ret->required_count = 0;
@ -863,7 +863,7 @@ upb_MiniTable* upb_MiniTable_BuildMapEntry(upb_FieldType key_type,
ret->size = UPB_ALIGN_UP(2 * field_size, 8); ret->size = UPB_ALIGN_UP(2 * field_size, 8);
ret->field_count = 2; ret->field_count = 2;
ret->ext = upb_ExtMode_NonExtendable | upb_ExtMode_IsMapEntry; ret->ext = kUpb_ExtMode_NonExtendable | kUpb_ExtMode_IsMapEntry;
ret->dense_below = 2; ret->dense_below = 2;
ret->table_mask = 0; ret->table_mask = 0;
ret->required_count = 0; ret->required_count = 0;
@ -919,7 +919,7 @@ void upb_MiniTable_SetSubMessage(upb_MiniTable* table,
const upb_MiniTable* sub) { const upb_MiniTable* sub) {
assert((uintptr_t)table->fields <= (uintptr_t)field && assert((uintptr_t)table->fields <= (uintptr_t)field &&
(uintptr_t)field < (uintptr_t)(table->fields + table->field_count)); (uintptr_t)field < (uintptr_t)(table->fields + table->field_count));
if (sub->ext & upb_ExtMode_IsMapEntry) { if (sub->ext & kUpb_ExtMode_IsMapEntry) {
field->mode = field->mode =
(kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift) | kUpb_FieldMode_Map; (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift) | kUpb_FieldMode_Map;
} }

@ -92,22 +92,13 @@ typedef enum {
kUpb_LabelFlags_IsExtension = 8, kUpb_LabelFlags_IsExtension = 8,
} upb_LabelFlags; } upb_LabelFlags;
/* Representation in the message. Derivable from descriptortype and mode, but
* fast access helps the serializer. */
typedef enum { typedef enum {
kUpb_FieldRep_1Byte = 0, kUpb_FieldRep_1Byte = 0,
kUpb_FieldRep_4Byte = 1, kUpb_FieldRep_4Byte = 1,
kUpb_FieldRep_8Byte = 2, kUpb_FieldRep_Pointer = 2,
kUpb_FieldRep_StringView = 3, kUpb_FieldRep_StringView = 3,
kUpb_FieldRep_8Byte = 4,
#if UINTPTR_MAX == 0xffffffff kUpb_FieldRep_Shift = 5, // Bit offset of the rep in upb_MiniTable_Field.mode
kUpb_FieldRep_Pointer = kUpb_FieldRep_4Byte,
#else
kUpb_FieldRep_Pointer = kUpb_FieldRep_8Byte,
#endif
kUpb_FieldRep_Shift =
6, /* Bit offset of the rep in upb_MiniTable_Field.mode */
} upb_FieldRep; } upb_FieldRep;
UPB_INLINE upb_FieldMode upb_FieldMode_Get(const upb_MiniTable_Field* field) { UPB_INLINE upb_FieldMode upb_FieldMode_Get(const upb_MiniTable_Field* field) {

Loading…
Cancel
Save