diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index a37e667e2f78..10474556d604 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1208,6 +1208,16 @@ UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { return (a.size == b.size) && (!a.size || !memcmp(a.data, b.data, a.size)); } +// Compares StringViews following strcmp rules. +// Please note this comparison is neither unicode nor locale aware. +UPB_INLINE int upb_StringView_Compare(upb_StringView a, upb_StringView b) { + int result = memcmp(a.data, b.data, UPB_MIN(a.size, b.size)); + if (result == 0) { + return a.size - b.size; + } + return result; +} + // LINT.ThenChange( // GoogleInternalName1, // //depot/google3/third_party/upb/bits/golang/accessor.go:map_go_string, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 33d0a07eb221..ea668e070b04 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1210,6 +1210,16 @@ UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { return (a.size == b.size) && (!a.size || !memcmp(a.data, b.data, a.size)); } +// Compares StringViews following strcmp rules. +// Please note this comparison is neither unicode nor locale aware. +UPB_INLINE int upb_StringView_Compare(upb_StringView a, upb_StringView b) { + int result = memcmp(a.data, b.data, UPB_MIN(a.size, b.size)); + if (result == 0) { + return a.size - b.size; + } + return result; +} + // LINT.ThenChange( // GoogleInternalName1, // //depot/google3/third_party/upb/bits/golang/accessor.go:map_go_string,