Skip to content

Commit 0913d39

Browse files
zhangskzadazh
andauthored
upb: Update _upb_map_next signature to return a boolean and remove the _nextmutable Map iterator API. (#20467)
PiperOrigin-RevId: 730964212 Co-authored-by: Ada Zhang <adazhang@google.com>
1 parent 0778473 commit 0913d39

File tree

4 files changed

+6
-20
lines changed

4 files changed

+6
-20
lines changed

php/ext/google/protobuf/php-upb.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,14 +2899,13 @@ UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) {
28992899
}
29002900
}
29012901

2902-
UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) {
2902+
UPB_INLINE bool _upb_map_next(const struct upb_Map* map, size_t* iter) {
29032903
upb_strtable_iter it;
29042904
it.t = &map->table;
29052905
it.index = *iter;
29062906
upb_strtable_next(&it);
29072907
*iter = it.index;
2908-
if (upb_strtable_done(&it)) return NULL;
2909-
return (void*)str_tabent(&it);
2908+
return !upb_strtable_done(&it);
29102909
}
29112910

29122911
UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) {

ruby/ext/google/protobuf_c/ruby-upb.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,14 +2901,13 @@ UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) {
29012901
}
29022902
}
29032903

2904-
UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) {
2904+
UPB_INLINE bool _upb_map_next(const struct upb_Map* map, size_t* iter) {
29052905
upb_strtable_iter it;
29062906
it.t = &map->table;
29072907
it.index = *iter;
29082908
upb_strtable_next(&it);
29092909
*iter = it.index;
2910-
if (upb_strtable_done(&it)) return NULL;
2911-
return (void*)str_tabent(&it);
2910+
return !upb_strtable_done(&it);
29122911
}
29132912

29142913
UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) {

upb/message/internal/map.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,13 @@ UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) {
9595
}
9696
}
9797

98-
UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) {
98+
UPB_INLINE bool _upb_map_next(const struct upb_Map* map, size_t* iter) {
9999
upb_strtable_iter it;
100100
it.t = &map->table;
101101
it.index = *iter;
102102
upb_strtable_next(&it);
103103
*iter = it.index;
104-
if (upb_strtable_done(&it)) return NULL;
105-
return (void*)str_tabent(&it);
104+
return !upb_strtable_done(&it);
106105
}
107106

108107
UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) {

upb_generator/c/generator.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -671,17 +671,6 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools,
671671
)cc",
672672
msg_name, resolved_name, MapKeyCType(field),
673673
FieldInitializer(pools, field, options), MapKeySize(field, "key"));
674-
output(
675-
R"cc(
676-
UPB_INLINE $0 $1_$2_nextmutable($1* msg, size_t* iter) {
677-
const upb_MiniTableField field = $3;
678-
upb_Map* map = (upb_Map*)upb_Message_GetMap(UPB_UPCAST(msg), &field);
679-
if (!map) return NULL;
680-
return ($0)_upb_map_next(map, iter);
681-
}
682-
)cc",
683-
CType(field), msg_name, resolved_name,
684-
FieldInitializerStrong(pools, field, options));
685674
}
686675

687676
void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools,

0 commit comments

Comments
 (0)