A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/protocolbuffers/protobuf/commit/dd5bf5e9b24d0462b981da05f4dcfd1499a4686c below:

Add upb_Map_GetMutable API to upb · protocolbuffers/protobuf@dd5bf5e · GitHub

File tree Expand file treeCollapse file tree 4 files changed

+24

-4

lines changed

Filter options

Expand file treeCollapse file tree 4 files changed

+24

-4

lines changed Original file line number Diff line number Diff line change

@@ -29,8 +29,8 @@ pub use extension_registry::{upb_ExtensionRegistry, RawExtensionRegistry};

29 29 30 30

mod map;

31 31

pub use map::{

32 -

upb_Map, upb_Map_Clear, upb_Map_Delete, upb_Map_Get, upb_Map_Insert, upb_Map_New, upb_Map_Next,

33 -

upb_Map_Size, MapInsertStatus, RawMap, UPB_MAP_BEGIN,

32 +

upb_Map, upb_Map_Clear, upb_Map_Delete, upb_Map_Get, upb_Map_GetMutable, upb_Map_Insert,

33 +

upb_Map_New, upb_Map_Next, upb_Map_Size, MapInsertStatus, RawMap, UPB_MAP_BEGIN,

34 34

};

35 35 36 36

mod message;

Original file line number Diff line number Diff line change

@@ -6,7 +6,7 @@

6 6

// https://developers.google.com/open-source/licenses/bsd

7 7 8 8

use super::opaque_pointee::opaque_pointee;

9 -

use super::{upb_MessageValue, CType, RawArena};

9 +

use super::{upb_Message, upb_MessageValue, CType, RawArena};

10 10

use core::ptr::NonNull;

11 11 12 12

opaque_pointee!(upb_Map);

@@ -33,6 +33,7 @@ extern "C" {

33 33

arena: RawArena,

34 34

) -> MapInsertStatus;

35 35

pub fn upb_Map_Get(map: RawMap, key: upb_MessageValue, value: *mut upb_MessageValue) -> bool;

36 +

pub fn upb_Map_GetMutable(map: RawMap, key: upb_MessageValue) -> *mut upb_Message;

36 37

pub fn upb_Map_Delete(

37 38

map: RawMap,

38 39

key: upb_MessageValue,

@@ -60,6 +61,7 @@ mod tests {

60 61

assert_linked!(upb_Map_Size);

61 62

assert_linked!(upb_Map_Insert);

62 63

assert_linked!(upb_Map_Get);

64 +

assert_linked!(upb_Map_GetMutable);

63 65

assert_linked!(upb_Map_Delete);

64 66

assert_linked!(upb_Map_Clear);

65 67

assert_linked!(upb_Map_Next);

Original file line number Diff line number Diff line change

@@ -17,6 +17,7 @@

17 17

#include "upb/hash/str_table.h"

18 18

#include "upb/mem/arena.h"

19 19

#include "upb/message/internal/map.h"

20 +

#include "upb/message/internal/types.h"

20 21

#include "upb/message/map.h"

21 22

#include "upb/message/message.h"

22 23

#include "upb/message/value.h"

@@ -52,6 +53,16 @@ bool upb_Map_Get(const upb_Map* map, upb_MessageValue key,

52 53

return _upb_Map_Get(map, &key, map->key_size, val, map->val_size);

53 54

}

54 55 56 +

struct upb_Message* upb_Map_GetMutable(upb_Map* map, upb_MessageValue key) {

57 +

UPB_ASSERT(map->val_size == sizeof(upb_Message*));

58 +

upb_Message* val = NULL;

59 +

if (_upb_Map_Get(map, &key, map->key_size, &val, sizeof(upb_Message*))) {

60 +

return val;

61 +

} else {

62 +

return NULL;

63 +

}

64 +

}

65 + 55 66

void upb_Map_Clear(upb_Map* map) { _upb_Map_Clear(map); }

56 67 57 68

upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key,

Original file line number Diff line number Diff line change

@@ -13,6 +13,7 @@

13 13

#include "upb/base/descriptor_constants.h"

14 14

#include "upb/mem/arena.h"

15 15

#include "upb/message/internal/map.h"

16 +

#include "upb/message/internal/types.h"

16 17

#include "upb/message/value.h"

17 18

#include "upb/mini_table/field.h"

18 19

#include "upb/mini_table/message.h"

@@ -39,6 +40,12 @@ UPB_API size_t upb_Map_Size(const upb_Map* map);

39 40

UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key,

40 41

upb_MessageValue* val);

41 42 43 +

// Returns a mutable pointer to the value for the given key. Returns NULL if the

44 +

// key is not present.

45 +

// This function is only legal to call for maps that contain messages.

46 +

UPB_API struct upb_Message* upb_Map_GetMutable(upb_Map* map,

47 +

upb_MessageValue key);

48 + 42 49

// Removes all entries in the map.

43 50

UPB_API void upb_Map_Clear(upb_Map* map);

44 51

@@ -71,7 +78,7 @@ UPB_API bool upb_Map_Delete(upb_Map* map, upb_MessageValue key,

71 78

// ...

72 79

// }

73 80 74 -

#define kUpb_Map_Begin ((size_t) - 1)

81 +

#define kUpb_Map_Begin ((size_t)-1)

75 82 76 83

// Advances to the next entry. Returns false if no more entries are present.

77 84

// Otherwise returns true and populates both *key and *value.

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4