update Ruby to use the newer upb_Map_Next() iterator

also update protobuf_defs.bzl to point to the latest upb commit, to pull in upb_Map_Next()

PiperOrigin-RevId: 490052254
pull/11039/head
Eric Salo 2 years ago committed by Copybara-Service
parent 9cdf347d19
commit 8809a113bc
  1. 19543
      php/ext/google/protobuf/php-upb.c
  2. 4819
      php/ext/google/protobuf/php-upb.h
  3. 4
      protobuf_deps.bzl
  4. 52
      ruby/ext/google/protobuf_c/map.c
  5. 18917
      ruby/ext/google/protobuf_c/ruby-upb.c
  6. 4917
      ruby/ext/google/protobuf_c/ruby-upb.h

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -135,6 +135,6 @@ def protobuf_deps():
_github_archive(
name = "upb",
repo = "https://github.com/protocolbuffers/upb",
commit = "73661563dbb82bf7fdd614dd8da1186c0acc6b17",
sha256 = "0b2789aa957c665165fa66892a6402489d6491cb097391fd8ea5b5a248dbde35",
commit = "2644ae7507f8ca6c194b77fdebb71b3a57c8428c",
sha256 = "7cc1874ac409ce2c2dc71669a26471e22d5b02c340f895664aa923af08c58d19",
)

@ -133,14 +133,13 @@ static upb_Map* Map_GetMutable(VALUE _self) {
VALUE Map_CreateHash(const upb_Map* map, upb_CType key_type,
TypeInfo val_info) {
VALUE hash = rb_hash_new();
size_t iter = kUpb_Map_Begin;
TypeInfo key_info = TypeInfo_from_type(key_type);
if (!map) return hash;
while (upb_MapIterator_Next(map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(map, iter);
upb_MessageValue val = upb_MapIterator_Value(map, iter);
size_t iter = kUpb_Map_Begin;
upb_MessageValue key, val;
while (upb_Map_Next(map, &key, &val, &iter)) {
VALUE key_val = Convert_UpbToRuby(key, key_info, Qnil);
VALUE val_val = Scalar_CreateHash(val, val_info);
rb_hash_aset(hash, key_val, val_val);
@ -156,9 +155,8 @@ VALUE Map_deep_copy(VALUE obj) {
upb_Map* new_map =
upb_Map_New(arena, self->key_type, self->value_type_info.type);
size_t iter = kUpb_Map_Begin;
while (upb_MapIterator_Next(self->map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
upb_MessageValue key, val;
while (upb_Map_Next(self->map, &key, &val, &iter)) {
upb_MessageValue val_copy =
Msgval_DeepCopy(val, self->value_type_info, arena);
upb_Map_Set(new_map, key, val_copy, arena);
@ -202,9 +200,8 @@ void Map_Inspect(StringBuilder* b, const upb_Map* map, upb_CType key_type,
StringBuilder_Printf(b, "{");
if (map) {
size_t iter = kUpb_Map_Begin;
while (upb_MapIterator_Next(map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(map, iter);
upb_MessageValue val = upb_MapIterator_Value(map, iter);
upb_MessageValue key, val;
while (upb_Map_Next(map, &key, &val, &iter)) {
if (first) {
first = false;
} else {
@ -239,7 +236,6 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
Map* other = ruby_to_Map(hashmap);
upb_Arena* arena = Arena_get(self->arena);
upb_Message* self_msg = Map_GetMutable(_self);
size_t iter = kUpb_Map_Begin;
Arena_fuse(other->arena, arena);
@ -249,9 +245,9 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
rb_raise(rb_eArgError, "Attempt to merge Map with mismatching types");
}
while (upb_MapIterator_Next(other->map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(other->map, iter);
upb_MessageValue val = upb_MapIterator_Value(other->map, iter);
size_t iter = kUpb_Map_Begin;
upb_MessageValue key, val;
while (upb_Map_Next(other->map, &key, &val, &iter)) {
upb_Map_Set(self_msg, key, val, arena);
}
} else {
@ -343,10 +339,9 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
static VALUE Map_each(VALUE _self) {
Map* self = ruby_to_Map(_self);
size_t iter = kUpb_Map_Begin;
upb_MessageValue key, val;
while (upb_MapIterator_Next(self->map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
while (upb_Map_Next(self->map, &key, &val, &iter)) {
VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
rb_yield_values(2, key_val, val_val);
@ -365,9 +360,9 @@ static VALUE Map_keys(VALUE _self) {
Map* self = ruby_to_Map(_self);
size_t iter = kUpb_Map_Begin;
VALUE ret = rb_ary_new();
upb_MessageValue key, val;
while (upb_MapIterator_Next(self->map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
while (upb_Map_Next(self->map, &key, &val, &iter)) {
VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena);
rb_ary_push(ret, key_val);
}
@ -385,9 +380,9 @@ static VALUE Map_values(VALUE _self) {
Map* self = ruby_to_Map(_self);
size_t iter = kUpb_Map_Begin;
VALUE ret = rb_ary_new();
upb_MessageValue key, val;
while (upb_MapIterator_Next(self->map, &iter)) {
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
while (upb_Map_Next(self->map, &key, &val, &iter)) {
VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena);
rb_ary_push(ret, val_val);
}
@ -523,9 +518,8 @@ static VALUE Map_dup(VALUE _self) {
Arena_fuse(self->arena, arena);
while (upb_MapIterator_Next(self->map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
upb_MessageValue key, val;
while (upb_Map_Next(self->map, &key, &val, &iter)) {
upb_Map_Set(new_map, key, val, arena);
}
@ -574,9 +568,8 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
// For each member of self, check that an equal member exists at the same key
// in other.
size_t iter = kUpb_Map_Begin;
while (upb_MapIterator_Next(self->map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
upb_MessageValue key, val;
while (upb_Map_Next(self->map, &key, &val, &iter)) {
upb_MessageValue other_val;
if (!upb_Map_Get(other->map, key, &other_val)) {
// Not present in other map.
@ -619,9 +612,8 @@ VALUE Map_hash(VALUE _self) {
size_t iter = kUpb_Map_Begin;
TypeInfo key_info = {self->key_type};
while (upb_MapIterator_Next(self->map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(self->map, iter);
upb_MessageValue val = upb_MapIterator_Value(self->map, iter);
upb_MessageValue key, val;
while (upb_Map_Next(self->map, &key, &val, &iter)) {
hash = Msgval_GetHash(key, key_info, hash);
hash = Msgval_GetHash(val, self->value_type_info, hash);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save