upb: add 'static' to UPB_FORCEINLINE()

PiperOrigin-RevId: 601525709
pull/15592/head
Eric Salo 1 year ago committed by Copybara-Service
parent 02c675e99e
commit 5bded04d28
  1. 2
      upb/message/internal/accessors.h
  2. 6
      upb/port/def.inc
  3. 103
      upb/wire/decode.c
  4. 4
      upb/wire/encode.c
  5. 6
      upb/wire/eps_copy_input_stream.h
  6. 54
      upb/wire/internal/decode_fast.c
  7. 2
      upb/wire/internal/reader.h
  8. 4
      upb/wire/reader.h

@ -243,7 +243,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_HasExtension)(
return UPB_PRIVATE(_upb_Message_Getext)(msg, ext) != NULL; return UPB_PRIVATE(_upb_Message_Getext)(msg, ext) != NULL;
} }
static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( UPB_FORCEINLINE void _upb_Message_GetNonExtensionField(
const struct upb_Message* msg, const upb_MiniTableField* field, const struct upb_Message* msg, const upb_MiniTableField* field,
const void* default_val, void* val) { const void* default_val, void* val) {
UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); UPB_ASSUME(!upb_MiniTableField_IsExtension(field));

@ -117,17 +117,17 @@ Error, UINTPTR_MAX is undefined
// Macros for function attributes on compilers that support them. // Macros for function attributes on compilers that support them.
#ifdef __GNUC__ #ifdef __GNUC__
#define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) #define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) static
#define UPB_NOINLINE __attribute__((noinline)) #define UPB_NOINLINE __attribute__((noinline))
#define UPB_NORETURN __attribute__((__noreturn__)) #define UPB_NORETURN __attribute__((__noreturn__))
#define UPB_PRINTF(str, first_vararg) __attribute__((format (printf, str, first_vararg))) #define UPB_PRINTF(str, first_vararg) __attribute__((format (printf, str, first_vararg)))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define UPB_NOINLINE #define UPB_NOINLINE
#define UPB_FORCEINLINE #define UPB_FORCEINLINE static
#define UPB_NORETURN __declspec(noreturn) #define UPB_NORETURN __declspec(noreturn)
#define UPB_PRINTF(str, first_vararg) #define UPB_PRINTF(str, first_vararg)
#else /* !defined(__GNUC__) */ #else /* !defined(__GNUC__) */
#define UPB_FORCEINLINE #define UPB_FORCEINLINE static
#define UPB_NOINLINE #define UPB_NOINLINE
#define UPB_NORETURN #define UPB_NORETURN
#define UPB_PRINTF(str, first_vararg) #define UPB_PRINTF(str, first_vararg)

@ -166,8 +166,8 @@ static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint(
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr,
uint64_t* val) { uint64_t* val) {
uint64_t byte = (uint8_t)*ptr; uint64_t byte = (uint8_t)*ptr;
if (UPB_LIKELY((byte & 0x80) == 0)) { if (UPB_LIKELY((byte & 0x80) == 0)) {
*val = byte; *val = byte;
@ -181,8 +181,8 @@ static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr,
uint32_t* val) { uint32_t* val) {
uint64_t byte = (uint8_t)*ptr; uint64_t byte = (uint8_t)*ptr;
if (UPB_LIKELY((byte & 0x80) == 0)) { if (UPB_LIKELY((byte & 0x80) == 0)) {
*val = byte; *val = byte;
@ -199,8 +199,8 @@ static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr,
uint32_t* size) { uint32_t* size) {
uint64_t size64; uint64_t size64;
ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64); ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64);
if (size64 >= INT32_MAX || if (size64 >= INT32_MAX ||
@ -302,11 +302,10 @@ static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, const char* ptr,
const char* ptr, upb_Message* submsg,
upb_Message* submsg, const upb_MiniTable* subl,
const upb_MiniTable* subl, uint32_t expected_end_group) {
uint32_t expected_end_group) {
if (--d->depth < 0) { if (--d->depth < 0) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded);
} }
@ -319,9 +318,11 @@ static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeSubMessage( const char* _upb_Decoder_DecodeSubMessage(upb_Decoder* d, const char* ptr,
upb_Decoder* d, const char* ptr, upb_Message* submsg, upb_Message* submsg,
const upb_MiniTableSub* subs, const upb_MiniTableField* field, int size) { const upb_MiniTableSub* subs,
const upb_MiniTableField* field,
int size) {
int saved_delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size); int saved_delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size);
const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field);
UPB_ASSERT(subl); UPB_ASSERT(subl);
@ -331,10 +332,10 @@ static const char* _upb_Decoder_DecodeSubMessage(
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr,
upb_Message* submsg, upb_Message* submsg,
const upb_MiniTable* subl, const upb_MiniTable* subl,
uint32_t number) { uint32_t number) {
if (_upb_Decoder_IsDone(d, &ptr)) { if (_upb_Decoder_IsDone(d, &ptr)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
} }
@ -344,16 +345,16 @@ static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, const char* ptr,
const char* ptr, uint32_t number) {
uint32_t number) {
return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number); return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number);
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeKnownGroup( const char* _upb_Decoder_DecodeKnownGroup(upb_Decoder* d, const char* ptr,
upb_Decoder* d, const char* ptr, upb_Message* submsg, upb_Message* submsg,
const upb_MiniTableSub* subs, const upb_MiniTableField* field) { const upb_MiniTableSub* subs,
const upb_MiniTableField* field) {
const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field);
UPB_ASSERT(subl); UPB_ASSERT(subl);
return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl,
@ -383,10 +384,9 @@ static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, upb_Message* msg,
upb_Message* msg, const upb_MiniTableEnum* e, const upb_MiniTableEnum* e,
const upb_MiniTableField* field, const upb_MiniTableField* field, wireval* val) {
wireval* val) {
const uint32_t v = val->uint32_val; const uint32_t v = val->uint32_val;
if (UPB_LIKELY(upb_MiniTableEnum_CheckValue(e, v))) return true; if (UPB_LIKELY(upb_MiniTableEnum_CheckValue(e, v))) return true;
@ -420,9 +420,10 @@ static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeFixedPacked( const char* _upb_Decoder_DecodeFixedPacked(upb_Decoder* d, const char* ptr,
upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, upb_Array* arr, wireval* val,
const upb_MiniTableField* field, int lg2) { const upb_MiniTableField* field,
int lg2) {
int mask = (1 << lg2) - 1; int mask = (1 << lg2) - 1;
size_t count = val->size >> lg2; size_t count = val->size >> lg2;
if ((val->size & mask) != 0) { if ((val->size & mask) != 0) {
@ -457,9 +458,10 @@ static const char* _upb_Decoder_DecodeFixedPacked(
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeVarintPacked( const char* _upb_Decoder_DecodeVarintPacked(upb_Decoder* d, const char* ptr,
upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, upb_Array* arr, wireval* val,
const upb_MiniTableField* field, int lg2) { const upb_MiniTableField* field,
int lg2) {
int scale = 1 << lg2; int scale = 1 << lg2;
int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size);
char* out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr), char* out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr),
@ -765,9 +767,8 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr, bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr,
upb_Message* msg, upb_Message* msg, const upb_MiniTable* m) {
const upb_MiniTable* m) {
#if UPB_FASTTABLE #if UPB_FASTTABLE
if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) { if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) {
uint16_t tag = _upb_FastDecoder_LoadTag(*ptr); uint16_t tag = _upb_FastDecoder_LoadTag(*ptr);
@ -1005,9 +1006,8 @@ static int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) {
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt,
const upb_MiniTableField* field, const upb_MiniTableField* field, int* op) {
int* op) {
// If sub-message is not linked, treat as unknown. // If sub-message is not linked, treat as unknown.
if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return; if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return;
const upb_MiniTable* mt_sub = const upb_MiniTable* mt_sub =
@ -1033,9 +1033,8 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d, void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d,
const upb_MiniTableField* field, const upb_MiniTableField* field, int* op) {
int* op) {
if ((field->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) && if ((field->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) &&
UPB_UNLIKELY(d->options & kUpb_DecodeOption_AlwaysValidateUtf8)) UPB_UNLIKELY(d->options & kUpb_DecodeOption_AlwaysValidateUtf8))
*op = kUpb_DecodeOp_String; *op = kUpb_DecodeOp_String;
@ -1105,11 +1104,10 @@ static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
const upb_MiniTable* mt, const upb_MiniTable* mt,
const upb_MiniTableField* field, const upb_MiniTableField* field,
int wire_type, wireval* val, int wire_type, wireval* val, int* op) {
int* op) {
static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) | static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) |
(1 << kUpb_FieldType_Fixed32) | (1 << kUpb_FieldType_Fixed32) |
(1 << kUpb_FieldType_SFixed32); (1 << kUpb_FieldType_SFixed32);
@ -1159,10 +1157,11 @@ static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* _upb_Decoder_DecodeKnownField( const char* _upb_Decoder_DecodeKnownField(upb_Decoder* d, const char* ptr,
upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Message* msg,
const upb_MiniTable* layout, const upb_MiniTableField* field, int op, const upb_MiniTable* layout,
wireval* val) { const upb_MiniTableField* field,
int op, wireval* val) {
const upb_MiniTableSub* subs = layout->UPB_PRIVATE(subs); const upb_MiniTableSub* subs = layout->UPB_PRIVATE(subs);
uint8_t mode = field->UPB_PRIVATE(mode); uint8_t mode = field->UPB_PRIVATE(mode);

@ -113,7 +113,7 @@ static void encode_growbuffer(upb_encstate* e, size_t bytes) {
/* Call to ensure that at least "bytes" bytes are available for writing at /* Call to ensure that at least "bytes" bytes are available for writing at
* e->ptr. Returns false if the bytes could not be allocated. */ * e->ptr. Returns false if the bytes could not be allocated. */
UPB_FORCEINLINE UPB_FORCEINLINE
static void encode_reserve(upb_encstate* e, size_t bytes) { void encode_reserve(upb_encstate* e, size_t bytes) {
if ((size_t)(e->ptr - e->buf) < bytes) { if ((size_t)(e->ptr - e->buf) < bytes) {
encode_growbuffer(e, bytes); encode_growbuffer(e, bytes);
return; return;
@ -152,7 +152,7 @@ static void encode_longvarint(upb_encstate* e, uint64_t val) {
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static void encode_varint(upb_encstate* e, uint64_t val) { void encode_varint(upb_encstate* e, uint64_t val) {
if (val < 128 && e->ptr != e->buf) { if (val < 128 && e->ptr != e->buf) {
--e->ptr; --e->ptr;
*e->ptr = val; *e->ptr = val;

@ -37,8 +37,8 @@ typedef struct {
const char* end; // Can read up to SlopBytes bytes beyond this. const char* end; // Can read up to SlopBytes bytes beyond this.
const char* limit_ptr; // For bounds checks, = end + UPB_MIN(limit, 0) const char* limit_ptr; // For bounds checks, = end + UPB_MIN(limit, 0)
uintptr_t aliasing; uintptr_t aliasing;
int limit; // Submessage limit relative to end int limit; // Submessage limit relative to end
bool error; // To distinguish between EOF and error. bool error; // To distinguish between EOF and error.
char patch[kUpb_EpsCopyInputStream_SlopBytes * 2]; char patch[kUpb_EpsCopyInputStream_SlopBytes * 2];
} upb_EpsCopyInputStream; } upb_EpsCopyInputStream;
@ -375,7 +375,7 @@ typedef const char* upb_EpsCopyInputStream_ParseDelimitedFunc(
// fits within this buffer, calls `func` with `ctx` as a parameter, where the // fits within this buffer, calls `func` with `ctx` as a parameter, where the
// pushing and popping of limits is handled automatically and with lower cost // pushing and popping of limits is handled automatically and with lower cost
// than the normal PushLimit()/PopLimit() sequence. // than the normal PushLimit()/PopLimit() sequence.
static UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast( UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast(
upb_EpsCopyInputStream* e, const char** ptr, int len, upb_EpsCopyInputStream* e, const char** ptr, int len,
upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) {
if (!upb_EpsCopyInputStream_CheckSubMessageSizeAvailable(e, *ptr, len)) { if (!upb_EpsCopyInputStream_CheckSubMessageSizeAvailable(e, *ptr, len)) {

@ -58,7 +58,7 @@ static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) {
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { const char* fastdecode_dispatch(UPB_PARSE_PARAMS) {
int overrun; int overrun;
switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) {
case kUpb_IsDoneStatus_Done: case kUpb_IsDoneStatus_Done:
@ -80,7 +80,7 @@ static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) {
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static bool fastdecode_checktag(uint16_t data, int tagbytes) { bool fastdecode_checktag(uint16_t data, int tagbytes) {
if (tagbytes == 1) { if (tagbytes == 1) {
return (data & 0xff) == 0; return (data & 0xff) == 0;
} else { } else {
@ -89,7 +89,7 @@ static bool fastdecode_checktag(uint16_t data, int tagbytes) {
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* fastdecode_longsize(const char* ptr, int* size) { const char* fastdecode_longsize(const char* ptr, int* size) {
int i; int i;
UPB_ASSERT(*size & 0x80); UPB_ASSERT(*size & 0x80);
*size &= 0xff; *size &= 0xff;
@ -109,7 +109,7 @@ static const char* fastdecode_longsize(const char* ptr, int* size) {
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* fastdecode_delimited( const char* fastdecode_delimited(
upb_Decoder* d, const char* ptr, upb_Decoder* d, const char* ptr,
upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) {
ptr++; ptr++;
@ -162,8 +162,8 @@ typedef struct {
} fastdecode_nextret; } fastdecode_nextret;
UPB_FORCEINLINE UPB_FORCEINLINE
static void* fastdecode_resizearr(upb_Decoder* d, void* dst, void* fastdecode_resizearr(upb_Decoder* d, void* dst, fastdecode_arr* farr,
fastdecode_arr* farr, int valbytes) { int valbytes) {
if (UPB_UNLIKELY(dst == farr->end)) { if (UPB_UNLIKELY(dst == farr->end)) {
size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); size_t old_capacity = farr->arr->UPB_PRIVATE(capacity);
size_t old_bytes = old_capacity * valbytes; size_t old_bytes = old_capacity * valbytes;
@ -181,7 +181,7 @@ static void* fastdecode_resizearr(upb_Decoder* d, void* dst,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) {
if (tagbytes == 1) { if (tagbytes == 1) {
return (uint8_t)tag == (uint8_t)data; return (uint8_t)tag == (uint8_t)data;
} else { } else {
@ -190,19 +190,17 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) {
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) {
int valbytes) {
farr->arr->UPB_PRIVATE(size) = farr->arr->UPB_PRIVATE(size) =
(size_t)((char*)dst - (char*)upb_Array_MutableDataPtr(farr->arr)) / (size_t)((char*)dst - (char*)upb_Array_MutableDataPtr(farr->arr)) /
valbytes; valbytes;
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst,
const char** ptr, const char** ptr,
fastdecode_arr* farr, fastdecode_arr* farr, uint64_t data,
uint64_t data, int tagbytes, int tagbytes, int valbytes) {
int valbytes) {
fastdecode_nextret ret; fastdecode_nextret ret;
dst = (char*)dst + valbytes; dst = (char*)dst + valbytes;
@ -224,16 +222,15 @@ static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) {
size_t ofs = data >> 48; size_t ofs = data >> 48;
return (char*)msg + ofs; return (char*)msg + ofs;
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, void* fastdecode_getfield(upb_Decoder* d, const char* ptr, upb_Message* msg,
upb_Message* msg, uint64_t* data, uint64_t* data, uint64_t* hasbits,
uint64_t* hasbits, fastdecode_arr* farr, fastdecode_arr* farr, int valbytes, upb_card card) {
int valbytes, upb_card card) {
switch (card) { switch (card) {
case CARD_s: { case CARD_s: {
uint8_t hasbit_index = *data >> 24; uint8_t hasbit_index = *data >> 24;
@ -272,7 +269,7 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr,
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { bool fastdecode_flippacked(uint64_t* data, int tagbytes) {
*data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype.
return fastdecode_checktag(*data, tagbytes); return fastdecode_checktag(*data, tagbytes);
} }
@ -288,7 +285,7 @@ static bool fastdecode_flippacked(uint64_t* data, int tagbytes) {
/* varint fields **************************************************************/ /* varint fields **************************************************************/
UPB_FORCEINLINE UPB_FORCEINLINE
static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) {
if (valbytes == 1) { if (valbytes == 1) {
return val != 0; return val != 0;
} else if (zigzag) { } else if (zigzag) {
@ -304,7 +301,7 @@ static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) {
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { const char* fastdecode_varint64(const char* ptr, uint64_t* val) {
ptr++; ptr++;
*val = (uint8_t)ptr[-1]; *val = (uint8_t)ptr[-1];
if (UPB_UNLIKELY(*val & 0x80)) { if (UPB_UNLIKELY(*val & 0x80)) {
@ -379,8 +376,8 @@ typedef struct {
} fastdecode_varintdata; } fastdecode_varintdata;
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e,
const char* ptr, void* ctx) { const char* ptr, void* ctx) {
upb_Decoder* d = (upb_Decoder*)e; upb_Decoder* d = (upb_Decoder*)e;
fastdecode_varintdata* data = ctx; fastdecode_varintdata* data = ctx;
void* dst = data->dst; void* dst = data->dst;
@ -659,9 +656,8 @@ static const char* fastdecode_longstring_noutf8(
} }
UPB_FORCEINLINE UPB_FORCEINLINE
static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy,
int copy, char* data, size_t data_offset, char* data, size_t data_offset, upb_StringView* dst) {
upb_StringView* dst) {
d->arena.UPB_PRIVATE(ptr) += copy; d->arena.UPB_PRIVATE(ptr) += copy;
dst->data = data + data_offset; dst->data = data + data_offset;
UPB_UNPOISON_MEMORY_REGION(data, copy); UPB_UNPOISON_MEMORY_REGION(data, copy);
@ -892,8 +888,8 @@ typedef struct {
} fastdecode_submsgdata; } fastdecode_submsgdata;
UPB_FORCEINLINE UPB_FORCEINLINE
static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, const char* ptr,
const char* ptr, void* ctx) { void* ctx) {
upb_Decoder* d = (upb_Decoder*)e; upb_Decoder* d = (upb_Decoder*)e;
fastdecode_submsgdata* submsg = ctx; fastdecode_submsgdata* submsg = ctx;
ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0);

@ -26,7 +26,7 @@ extern "C" {
UPB_PRIVATE(_upb_WireReader_LongVarint) UPB_PRIVATE(_upb_WireReader_LongVarint)
UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val); UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val);
static UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)(
const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) { const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) {
uint64_t byte = (uint8_t)*ptr; uint64_t byte = (uint8_t)*ptr;
if (UPB_LIKELY((byte & 0x80) == 0)) { if (UPB_LIKELY((byte & 0x80) == 0)) {

@ -32,8 +32,8 @@ extern "C" {
// REQUIRES: there must be at least 10 bytes of data available at `ptr`. // REQUIRES: there must be at least 10 bytes of data available at `ptr`.
// Bounds checks must be performed before calling this function, preferably // Bounds checks must be performed before calling this function, preferably
// by calling upb_EpsCopyInputStream_IsDone(). // by calling upb_EpsCopyInputStream_IsDone().
static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr,
uint32_t* tag) { uint32_t* tag) {
uint64_t val; uint64_t val;
ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX); ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX);
if (!ptr) return NULL; if (!ptr) return NULL;

Loading…
Cancel
Save