Skip to content

Commit

Permalink
create upb/hash/
Browse files Browse the repository at this point in the history
The next lowest build target to scrub is the hash table. We already have a few
other things called 'table' (mini table, fast table) so let's just go with
'hash' here. Split apart the headers into int and str branches sharing common
definitions. Leave the core functions in a single .c for inlining.

PiperOrigin-RevId: 488388767
  • Loading branch information
ericsalo authored and copybara-github committed Nov 14, 2022
1 parent ff8e1b4 commit b3cb3fb
Show file tree
Hide file tree
Showing 20 changed files with 555 additions and 491 deletions.
54 changes: 27 additions & 27 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ cc_library(
srcs = [
"upb/collections/map_sorter_internal.h",
"upb/collections/message_value.h",
"upb/internal/table.h",
"upb/internal/unicode.h",
"upb/msg.c",
"upb/msg_internal.h",
Expand Down Expand Up @@ -152,9 +151,9 @@ cc_library(
":collections_internal",
":extension_registry",
":fastdecode",
":hash",
":mem",
":port",
":table_internal",
":unicode_internal",
":wire_internal",
],
Expand Down Expand Up @@ -192,8 +191,9 @@ cc_library(
deps = [
":base",
":collections_internal",
":hash",
":mem",
":port",
":table_internal",
],
)

Expand All @@ -213,8 +213,8 @@ cc_library(
":base",
":collections_internal",
":extension_registry",
":hash",
":port",
":table_internal",
":upb",
],
)
Expand All @@ -240,9 +240,9 @@ cc_library(
":base",
":collections_internal",
":extension_registry",
":hash",
":mini_table_internal",
":port",
":table_internal",
":upb",
],
)
Expand All @@ -261,10 +261,9 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":collections_internal",
":mini_table",
":hash",
":mini_table_internal",
":port",
":table_internal",
":upb",
],
)
Expand All @@ -276,10 +275,10 @@ cc_test(
],
deps = [
":extension_registry",
":hash",
":mini_table",
":mini_table_internal",
":port",
":table_internal",
":upb",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_googletest//:gtest_main",
Expand Down Expand Up @@ -321,9 +320,9 @@ cc_library(
":base",
":collections_internal",
":extension_registry",
":hash",
":mem_internal",
":port",
":table_internal",
":wire_internal",
],
)
Expand Down Expand Up @@ -357,7 +356,7 @@ cc_library(
deps = [
":base",
":collections_internal",
":table_internal",
":hash",
":upb",
],
)
Expand All @@ -380,8 +379,8 @@ cc_library(
deps = [
":base",
":collections_internal",
":hash",
":mini_table",
":table_internal",
":upb",
],
)
Expand Down Expand Up @@ -413,8 +412,8 @@ cc_library(
deps = [
":base",
":descriptor_upb_proto",
":hash",
":reflection_internal",
":table_internal",
],
)

Expand Down Expand Up @@ -468,9 +467,9 @@ cc_library(
visibility = ["//:__subpackages__"],
deps = [
":base",
":hash",
":mem",
":port",
":table_internal",
],
)

Expand Down Expand Up @@ -551,10 +550,10 @@ cc_library(
deps = [
":collections",
":descriptor_upb_proto",
":hash",
":mini_table",
":mini_table_internal",
":port",
":table_internal",
":upb",
],
)
Expand Down Expand Up @@ -617,10 +616,10 @@ cc_test(
],
deps = [
":descriptor_upb_proto",
":hash",
":port",
":reflection",
":reflection_internal",
":table_internal",
":upb",
"@com_google_googletest//:gtest_main",
],
Expand Down Expand Up @@ -847,12 +846,12 @@ cc_test(
)

cc_test(
name = "test_table",
srcs = ["upb/test_table.cc"],
name = "hash_test",
srcs = ["upb/hash/test.cc"],
copts = UPB_DEFAULT_CPPOPTS,
deps = [
":hash",
":port",
":table_internal",
":upb",
"@com_google_googletest//:gtest_main",
],
Expand Down Expand Up @@ -1034,28 +1033,28 @@ cc_library(
deps = [
":base",
":collections_internal",
":hash",
":mem_internal",
":port",
":table_internal",
"//third_party/utf8_range",
],
)

cc_library(
name = "table_internal",
name = "hash",
srcs = [
"upb/internal/table.c",
"upb/hash/common.c",
],
hdrs = [
"upb/internal/table.h",
"upb/mem/alloc.h",
"upb/mem/arena.h",
"upb/upb.h",
"upb/hash/common.h",
"upb/hash/int_table.h",
"upb/hash/str_table.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//:__subpackages__"],
deps = [
":base",
":mem",
":port",
],
)
Expand Down Expand Up @@ -1090,6 +1089,7 @@ upb_amalgamation(
":descriptor_upb_proto",
":extension_registry",
":fastdecode",
":hash",
":mem_internal",
":mini_table",
":mini_table_accessors",
Expand Down Expand Up @@ -1124,14 +1124,14 @@ upb_amalgamation(
":descriptor_upb_proto_reflection",
":extension_registry",
":fastdecode",
":hash",
":json",
":mem_internal",
":mini_table",
":mini_table_accessors",
":port",
":reflection",
":reflection_internal",
":table_internal",
":unicode_internal",
":upb",
":wire_internal",
Expand Down Expand Up @@ -1162,14 +1162,14 @@ upb_amalgamation(
":descriptor_upb_proto",
":extension_registry",
":fastdecode",
":hash",
":json",
":mem_internal",
":mini_table",
":mini_table_accessors",
":port",
":reflection",
":reflection_internal",
":table_internal",
":unicode_internal",
":upb",
":wire_internal",
Expand Down
2 changes: 1 addition & 1 deletion python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ py_extension(
deps = [
"//:collections",
"//:descriptor_upb_proto_reflection",
"//:hash",
"//:port",
"//:reflection",
"//:table_internal",
"//:textformat",
"//:upb",
"//upb/util:compare",
Expand Down
1 change: 1 addition & 0 deletions python/protobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "python/descriptor.h"
#include "python/python_api.h"
#include "upb/hash/int_table.h"

// begin:github_only
#define PYUPB_PROTOBUF_PUBLIC_PACKAGE "google.protobuf"
Expand Down
2 changes: 1 addition & 1 deletion upb/collections/map_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "upb/base/string_view.h"
#include "upb/collections/map.h"
#include "upb/internal/table.h"
#include "upb/hash/str_table.h"
#include "upb/mem/arena.h"

// Must be last.
Expand Down
2 changes: 1 addition & 1 deletion upb/extension_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "upb/extension_registry.h"

#include "upb/internal/table.h"
#include "upb/hash/str_table.h"
#include "upb/msg.h"
#include "upb/msg_internal.h"

Expand Down
4 changes: 2 additions & 2 deletions upb/internal/table.c → upb/hash/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
* Implementation is heavily inspired by Lua's ltable.c.
*/

#include "upb/internal/table.h"

#include <string.h>

#include "upb/base/log2.h"
#include "upb/hash/int_table.h"
#include "upb/hash/str_table.h"

// Must be last.
#include "upb/port/def.inc"
Expand Down
Loading

0 comments on commit b3cb3fb

Please sign in to comment.