grpc 1.31.1 → 1.32.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (431) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +595 -15723
  3. data/include/grpc/grpc_security.h +31 -14
  4. data/include/grpc/impl/codegen/README.md +22 -0
  5. data/include/grpc/impl/codegen/port_platform.h +6 -1
  6. data/src/core/ext/filters/client_channel/backup_poller.cc +3 -2
  7. data/src/core/ext/filters/client_channel/client_channel.cc +64 -20
  8. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  9. data/src/core/ext/filters/client_channel/client_channel_channelz.h +0 -3
  10. data/src/core/ext/filters/client_channel/health/health_check_client.cc +6 -1
  11. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -3
  12. data/src/core/ext/filters/client_channel/lb_policy.h +2 -0
  13. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +6 -4
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +20 -13
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +0 -13
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +0 -3
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -37
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +19 -13
  19. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +29 -10
  20. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -4
  21. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +20 -9
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +18 -12
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +22 -14
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +18 -9
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +54 -56
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +3 -3
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  29. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +1 -1
  30. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +363 -14
  32. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +0 -1
  33. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +5 -4
  34. data/src/core/ext/filters/client_channel/server_address.cc +40 -7
  35. data/src/core/ext/filters/client_channel/server_address.h +42 -4
  36. data/src/core/ext/filters/client_channel/subchannel.cc +64 -23
  37. data/src/core/ext/filters/client_channel/subchannel.h +16 -4
  38. data/src/core/ext/filters/max_age/max_age_filter.cc +2 -1
  39. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +87 -31
  40. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +18 -1
  41. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +10 -35
  42. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +19 -25
  43. data/src/core/ext/transport/chttp2/server/chttp2_server.h +2 -1
  44. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +2 -2
  45. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +6 -6
  46. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +3 -2
  47. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +239 -277
  48. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
  49. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -2
  50. data/src/core/ext/transport/chttp2/transport/internal.h +5 -1
  51. data/src/core/ext/transport/chttp2/transport/parsing.cc +1 -28
  52. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -5
  53. data/src/core/ext/transport/inproc/inproc_transport.cc +12 -12
  54. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +224 -0
  55. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +700 -0
  56. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +74 -0
  57. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +226 -0
  58. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +380 -0
  59. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +1378 -0
  60. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/filter.upb.c +8 -8
  61. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +69 -0
  62. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/outlier_detection.upb.c +8 -8
  63. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +323 -0
  64. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +112 -0
  65. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +334 -0
  66. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/backoff.upb.c +8 -8
  67. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +79 -0
  68. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +309 -0
  69. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +869 -0
  70. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +96 -0
  71. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +328 -0
  72. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +34 -0
  73. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +71 -0
  74. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +195 -0
  75. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +634 -0
  76. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +170 -0
  77. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +684 -0
  78. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/http_uri.upb.c +8 -8
  79. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +80 -0
  80. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +152 -0
  81. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +536 -0
  82. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +28 -0
  83. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +58 -0
  84. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/socket_option.upb.c +6 -6
  85. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +88 -0
  86. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +91 -0
  87. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +220 -0
  88. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +91 -0
  89. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +273 -0
  90. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +112 -0
  91. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +332 -0
  92. data/src/core/ext/upb-generated/envoy/config/listener/{v2 → v3}/api_listener.upb.c +8 -8
  93. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +65 -0
  94. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +108 -0
  95. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +401 -0
  96. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +138 -0
  97. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +490 -0
  98. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +41 -0
  99. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +94 -0
  100. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +174 -0
  101. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +599 -0
  102. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +63 -0
  103. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +204 -0
  104. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +773 -0
  105. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +2855 -0
  106. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +59 -0
  107. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +135 -0
  108. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +50 -0
  109. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +108 -0
  110. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +312 -0
  111. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +1125 -0
  112. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c +20 -0
  113. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +34 -0
  114. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +111 -0
  115. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +401 -0
  116. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +72 -0
  117. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +198 -0
  118. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +105 -0
  119. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +388 -0
  120. data/src/core/ext/upb-generated/envoy/{api/v2 → service/cluster/v3}/cds.upb.c +5 -6
  121. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +49 -0
  122. data/src/core/ext/upb-generated/envoy/service/discovery/{v2 → v3}/ads.upb.c +5 -4
  123. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +49 -0
  124. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +129 -0
  125. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +386 -0
  126. data/src/core/ext/upb-generated/envoy/{api/v2 → service/endpoint/v3}/eds.upb.c +5 -6
  127. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +49 -0
  128. data/src/core/ext/upb-generated/envoy/{api/v2 → service/listener/v3}/lds.upb.c +5 -6
  129. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +49 -0
  130. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +55 -0
  131. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +136 -0
  132. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/rds.upb.c +5 -6
  133. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +49 -0
  134. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/srds.upb.c +5 -6
  135. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +49 -0
  136. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +47 -0
  137. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +114 -0
  138. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +35 -0
  139. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +77 -0
  140. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +34 -0
  141. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +71 -0
  142. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +64 -0
  143. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +145 -0
  144. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +53 -0
  145. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +127 -0
  146. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +63 -0
  147. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +188 -0
  148. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +88 -0
  149. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +258 -0
  150. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +90 -0
  151. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +250 -0
  152. data/src/core/ext/upb-generated/envoy/type/{http.upb.c → v3/http.upb.c} +2 -2
  153. data/src/core/ext/upb-generated/envoy/type/{http.upb.h → v3/http.upb.h} +8 -8
  154. data/src/core/ext/upb-generated/envoy/type/{percent.upb.c → v3/percent.upb.c} +9 -8
  155. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +86 -0
  156. data/src/core/ext/upb-generated/envoy/type/{range.upb.c → v3/range.upb.c} +12 -11
  157. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +111 -0
  158. data/src/core/ext/upb-generated/envoy/type/{semantic_version.upb.c → v3/semantic_version.upb.c} +6 -5
  159. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +61 -0
  160. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +234 -0
  161. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +759 -0
  162. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +36 -36
  163. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +1 -1
  164. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +27 -0
  165. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +53 -0
  166. data/src/core/ext/upb-generated/validate/validate.upb.c +11 -11
  167. data/src/core/ext/upb-generated/validate/validate.upb.h +1 -1
  168. data/src/core/ext/{filters/client_channel/xds → xds}/xds_api.cc +1045 -767
  169. data/src/core/ext/{filters/client_channel/xds → xds}/xds_api.h +114 -99
  170. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.cc +44 -2
  171. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.h +8 -3
  172. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel.h +4 -4
  173. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_args.h +3 -3
  174. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_secure.cc +2 -5
  175. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.cc +85 -417
  176. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.h +12 -45
  177. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.cc +2 -2
  178. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.h +3 -3
  179. data/src/core/lib/channel/channelz.cc +14 -15
  180. data/src/core/lib/channel/channelz.h +1 -1
  181. data/src/core/lib/channel/channelz_registry.cc +3 -1
  182. data/src/core/lib/gpr/sync_posix.cc +2 -8
  183. data/src/core/lib/iomgr/endpoint.cc +5 -1
  184. data/src/core/lib/iomgr/endpoint.h +7 -3
  185. data/src/core/lib/iomgr/endpoint_cfstream.cc +32 -11
  186. data/src/core/lib/iomgr/ev_posix.cc +0 -2
  187. data/src/core/lib/iomgr/iomgr.cc +0 -10
  188. data/src/core/lib/iomgr/iomgr.h +0 -10
  189. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.cc +1 -1
  190. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.h +3 -3
  191. data/src/core/lib/iomgr/sockaddr_utils.cc +2 -1
  192. data/src/core/lib/iomgr/sockaddr_utils.h +2 -1
  193. data/src/core/lib/iomgr/tcp_custom.cc +32 -16
  194. data/src/core/lib/iomgr/tcp_posix.cc +31 -13
  195. data/src/core/lib/iomgr/tcp_windows.cc +26 -10
  196. data/src/core/lib/security/authorization/authorization_engine.cc +177 -0
  197. data/src/core/lib/security/authorization/authorization_engine.h +84 -0
  198. data/src/core/lib/security/authorization/evaluate_args.cc +153 -0
  199. data/src/core/lib/security/authorization/evaluate_args.h +59 -0
  200. data/src/core/lib/security/authorization/mock_cel/activation.h +57 -0
  201. data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +42 -0
  202. data/src/core/lib/security/authorization/mock_cel/cel_expression.h +68 -0
  203. data/src/core/lib/security/authorization/mock_cel/cel_value.h +93 -0
  204. data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +67 -0
  205. data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +56 -0
  206. data/src/core/lib/security/authorization/mock_cel/statusor.h +50 -0
  207. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +56 -38
  208. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +1 -2
  209. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  210. data/src/core/lib/surface/call.cc +12 -12
  211. data/src/core/lib/surface/call.h +2 -1
  212. data/src/core/lib/surface/channel.cc +28 -20
  213. data/src/core/lib/surface/channel.h +12 -2
  214. data/src/core/lib/surface/completion_queue.cc +10 -272
  215. data/src/core/lib/surface/completion_queue.h +0 -8
  216. data/src/core/lib/surface/init.cc +1 -3
  217. data/src/core/lib/surface/server.cc +1066 -1244
  218. data/src/core/lib/surface/server.h +363 -87
  219. data/src/core/lib/surface/version.cc +2 -2
  220. data/src/core/lib/transport/authority_override.cc +38 -0
  221. data/src/core/lib/transport/authority_override.h +32 -0
  222. data/src/core/lib/transport/connectivity_state.cc +18 -13
  223. data/src/core/lib/transport/connectivity_state.h +18 -6
  224. data/src/core/lib/transport/error_utils.cc +13 -0
  225. data/src/core/lib/transport/error_utils.h +6 -0
  226. data/src/core/lib/transport/static_metadata.cc +295 -276
  227. data/src/core/lib/transport/static_metadata.h +80 -73
  228. data/src/core/lib/transport/transport.h +7 -0
  229. data/src/core/lib/uri/uri_parser.cc +23 -21
  230. data/src/core/lib/uri/uri_parser.h +3 -1
  231. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +22 -0
  232. data/src/core/tsi/ssl_transport_security.cc +3 -9
  233. data/src/ruby/ext/grpc/rb_channel_credentials.c +9 -0
  234. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -2
  235. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -4
  236. data/src/ruby/lib/grpc/version.rb +1 -1
  237. data/src/ruby/spec/channel_credentials_spec.rb +10 -0
  238. data/src/ruby/spec/generic/active_call_spec.rb +19 -8
  239. data/third_party/abseil-cpp/absl/algorithm/container.h +1727 -0
  240. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +161 -0
  241. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.cc +93 -0
  242. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.h +130 -0
  243. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +620 -0
  244. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +126 -0
  245. data/third_party/abseil-cpp/absl/container/fixed_array.h +515 -0
  246. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +503 -0
  247. data/third_party/abseil-cpp/absl/container/internal/common.h +202 -0
  248. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +440 -0
  249. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +146 -0
  250. data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +191 -0
  251. data/third_party/abseil-cpp/absl/container/internal/hashtable_debug_hooks.h +85 -0
  252. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +269 -0
  253. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +297 -0
  254. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +30 -0
  255. data/third_party/abseil-cpp/absl/container/internal/have_sse.h +49 -0
  256. data/third_party/abseil-cpp/absl/container/internal/layout.h +741 -0
  257. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +48 -0
  258. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +1882 -0
  259. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +138 -0
  260. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.h +32 -0
  261. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +1895 -0
  262. data/third_party/abseil-cpp/absl/debugging/internal/demangle.h +71 -0
  263. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.cc +382 -0
  264. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +134 -0
  265. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +192 -0
  266. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +125 -0
  267. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +70 -0
  268. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +99 -0
  269. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +248 -0
  270. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_unimplemented-inl.inc +24 -0
  271. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +85 -0
  272. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +346 -0
  273. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +128 -0
  274. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +194 -0
  275. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.h +158 -0
  276. data/third_party/abseil-cpp/absl/debugging/stacktrace.cc +140 -0
  277. data/third_party/abseil-cpp/absl/debugging/stacktrace.h +231 -0
  278. data/third_party/abseil-cpp/absl/debugging/symbolize.cc +25 -0
  279. data/third_party/abseil-cpp/absl/debugging/symbolize.h +99 -0
  280. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +1480 -0
  281. data/third_party/abseil-cpp/absl/debugging/symbolize_unimplemented.inc +40 -0
  282. data/third_party/abseil-cpp/absl/debugging/symbolize_win32.inc +81 -0
  283. data/third_party/abseil-cpp/absl/functional/function_ref.h +139 -0
  284. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +106 -0
  285. data/third_party/abseil-cpp/absl/hash/hash.h +324 -0
  286. data/third_party/abseil-cpp/absl/hash/internal/city.cc +346 -0
  287. data/third_party/abseil-cpp/absl/hash/internal/city.h +96 -0
  288. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +55 -0
  289. data/third_party/abseil-cpp/absl/hash/internal/hash.h +988 -0
  290. data/third_party/abseil-cpp/absl/status/status.cc +447 -0
  291. data/third_party/abseil-cpp/absl/status/status.h +428 -0
  292. data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +43 -0
  293. data/third_party/abseil-cpp/absl/status/status_payload_printer.h +51 -0
  294. data/third_party/abseil-cpp/absl/strings/cord.cc +2019 -0
  295. data/third_party/abseil-cpp/absl/strings/cord.h +1121 -0
  296. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +151 -0
  297. data/third_party/abseil-cpp/absl/synchronization/barrier.cc +52 -0
  298. data/third_party/abseil-cpp/absl/synchronization/barrier.h +79 -0
  299. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.cc +57 -0
  300. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.h +99 -0
  301. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +140 -0
  302. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.h +60 -0
  303. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +697 -0
  304. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.h +141 -0
  305. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +155 -0
  306. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +261 -0
  307. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +106 -0
  308. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +115 -0
  309. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +484 -0
  310. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +159 -0
  311. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +2728 -0
  312. data/third_party/abseil-cpp/absl/synchronization/mutex.h +1056 -0
  313. data/third_party/abseil-cpp/absl/synchronization/notification.cc +78 -0
  314. data/third_party/abseil-cpp/absl/synchronization/notification.h +123 -0
  315. data/third_party/abseil-cpp/absl/types/bad_variant_access.cc +64 -0
  316. data/third_party/abseil-cpp/absl/types/bad_variant_access.h +82 -0
  317. data/third_party/abseil-cpp/absl/types/internal/variant.h +1646 -0
  318. data/third_party/abseil-cpp/absl/types/variant.h +861 -0
  319. data/third_party/boringssl-with-bazel/err_data.c +263 -257
  320. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +16 -0
  321. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +456 -0
  322. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +192 -0
  323. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +20 -0
  324. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +52 -0
  325. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +1 -1
  326. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +39 -7
  327. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +2 -3
  328. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +11 -0
  329. data/third_party/boringssl-with-bazel/src/ssl/internal.h +4 -0
  330. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +3 -6
  331. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +10 -0
  332. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +34 -9
  333. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +5 -0
  334. data/third_party/boringssl-with-bazel/src/ssl/tls_record.cc +5 -3
  335. data/third_party/upb/upb/decode.c +64 -15
  336. data/third_party/upb/upb/encode.c +2 -2
  337. data/third_party/upb/upb/msg.h +2 -2
  338. data/third_party/upb/upb/port_def.inc +1 -1
  339. data/third_party/upb/upb/table.c +0 -11
  340. data/third_party/upb/upb/table.int.h +0 -9
  341. data/third_party/upb/upb/upb.c +16 -14
  342. data/third_party/upb/upb/upb.h +26 -0
  343. data/third_party/upb/upb/upb.hpp +2 -0
  344. metadata +257 -155
  345. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +0 -21
  346. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +0 -34
  347. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +0 -114
  348. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +0 -429
  349. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +0 -72
  350. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +0 -198
  351. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +0 -105
  352. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +0 -388
  353. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +0 -52
  354. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +0 -403
  355. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +0 -1453
  356. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +0 -74
  357. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +0 -226
  358. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +0 -69
  359. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +0 -323
  360. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +0 -112
  361. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +0 -334
  362. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +0 -79
  363. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +0 -313
  364. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +0 -891
  365. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +0 -96
  366. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +0 -328
  367. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +0 -34
  368. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +0 -71
  369. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +0 -197
  370. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +0 -649
  371. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +0 -172
  372. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +0 -693
  373. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +0 -80
  374. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +0 -152
  375. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +0 -536
  376. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +0 -88
  377. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +0 -129
  378. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +0 -386
  379. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +0 -52
  380. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +0 -92
  381. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +0 -224
  382. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +0 -18
  383. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -32
  384. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +0 -91
  385. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +0 -273
  386. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +0 -112
  387. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +0 -332
  388. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +0 -52
  389. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +0 -109
  390. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +0 -415
  391. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +0 -18
  392. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -32
  393. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +0 -145
  394. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +0 -538
  395. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +0 -43
  396. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +0 -111
  397. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +0 -52
  398. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +0 -63
  399. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +0 -204
  400. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +0 -18
  401. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -32
  402. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +0 -815
  403. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +0 -2984
  404. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +0 -59
  405. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +0 -135
  406. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +0 -52
  407. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +0 -228
  408. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +0 -732
  409. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +0 -316
  410. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +0 -1167
  411. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +0 -65
  412. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +0 -51
  413. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +0 -125
  414. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +0 -49
  415. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +0 -54
  416. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +0 -136
  417. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +0 -63
  418. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +0 -145
  419. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +0 -53
  420. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +0 -133
  421. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +0 -88
  422. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +0 -258
  423. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +0 -86
  424. data/src/core/ext/upb-generated/envoy/type/range.upb.h +0 -111
  425. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +0 -61
  426. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +0 -89
  427. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +0 -250
  428. data/src/core/lib/security/transport/target_authority_table.cc +0 -75
  429. data/src/core/lib/security/transport/target_authority_table.h +0 -40
  430. data/src/core/lib/slice/slice_hash_table.h +0 -199
  431. data/src/core/lib/slice/slice_weak_hash_table.h +0 -102
@@ -0,0 +1,1121 @@
1
+ // Copyright 2020 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ // A Cord is a sequence of characters with some unusual access propreties.
16
+ // A Cord supports efficient insertions and deletions at the start and end of
17
+ // the byte sequence, but random access reads are slower, and random access
18
+ // modifications are not supported by the API. Cord also provides cheap copies
19
+ // (using a copy-on-write strategy) and cheap substring operations.
20
+ //
21
+ // Thread safety
22
+ // -------------
23
+ // Cord has the same thread-safety properties as many other types like
24
+ // std::string, std::vector<>, int, etc -- it is thread-compatible. In
25
+ // particular, if no thread may call a non-const method, then it is safe to
26
+ // concurrently call const methods. Copying a Cord produces a new instance that
27
+ // can be used concurrently with the original in arbitrary ways.
28
+ //
29
+ // Implementation is similar to the "Ropes" described in:
30
+ // Ropes: An alternative to strings
31
+ // Hans J. Boehm, Russ Atkinson, Michael Plass
32
+ // Software Practice and Experience, December 1995
33
+
34
+ #ifndef ABSL_STRINGS_CORD_H_
35
+ #define ABSL_STRINGS_CORD_H_
36
+
37
+ #include <algorithm>
38
+ #include <cstddef>
39
+ #include <cstdint>
40
+ #include <cstring>
41
+ #include <iostream>
42
+ #include <iterator>
43
+ #include <string>
44
+
45
+ #include "absl/base/internal/endian.h"
46
+ #include "absl/base/internal/invoke.h"
47
+ #include "absl/base/internal/per_thread_tls.h"
48
+ #include "absl/base/macros.h"
49
+ #include "absl/base/port.h"
50
+ #include "absl/container/inlined_vector.h"
51
+ #include "absl/functional/function_ref.h"
52
+ #include "absl/meta/type_traits.h"
53
+ #include "absl/strings/internal/cord_internal.h"
54
+ #include "absl/strings/internal/resize_uninitialized.h"
55
+ #include "absl/strings/string_view.h"
56
+
57
+ namespace absl {
58
+ ABSL_NAMESPACE_BEGIN
59
+ class Cord;
60
+ class CordTestPeer;
61
+ template <typename Releaser>
62
+ Cord MakeCordFromExternal(absl::string_view, Releaser&&);
63
+ void CopyCordToString(const Cord& src, std::string* dst);
64
+ namespace hash_internal {
65
+ template <typename H>
66
+ H HashFragmentedCord(H, const Cord&);
67
+ }
68
+
69
+ // A Cord is a sequence of characters.
70
+ class Cord {
71
+ private:
72
+ template <typename T>
73
+ using EnableIfString =
74
+ absl::enable_if_t<std::is_same<T, std::string>::value, int>;
75
+
76
+ public:
77
+ // --------------------------------------------------------------------
78
+ // Constructors, destructors and helper factories
79
+
80
+ // Create an empty cord
81
+ constexpr Cord() noexcept;
82
+
83
+ // Cord is copyable and efficiently movable.
84
+ // The moved-from state is valid but unspecified.
85
+ Cord(const Cord& src);
86
+ Cord(Cord&& src) noexcept;
87
+ Cord& operator=(const Cord& x);
88
+ Cord& operator=(Cord&& x) noexcept;
89
+
90
+ // Create a cord out of "src". This constructor is explicit on
91
+ // purpose so that people do not get automatic type conversions.
92
+ explicit Cord(absl::string_view src);
93
+ Cord& operator=(absl::string_view src);
94
+
95
+ // These are templated to avoid ambiguities for types that are convertible to
96
+ // both `absl::string_view` and `std::string`, such as `const char*`.
97
+ //
98
+ // Note that these functions reserve the right to reuse the `string&&`'s
99
+ // memory and that they will do so in the future.
100
+ template <typename T, EnableIfString<T> = 0>
101
+ explicit Cord(T&& src) : Cord(absl::string_view(src)) {}
102
+ template <typename T, EnableIfString<T> = 0>
103
+ Cord& operator=(T&& src);
104
+
105
+ // Destroy the cord
106
+ ~Cord() {
107
+ if (contents_.is_tree()) DestroyCordSlow();
108
+ }
109
+
110
+ // Creates a Cord that takes ownership of external memory. The contents of
111
+ // `data` are not copied.
112
+ //
113
+ // This function takes a callable that is invoked when all Cords are
114
+ // finished with `data`. The data must remain live and unchanging until the
115
+ // releaser is called. The requirements for the releaser are that it:
116
+ // * is move constructible,
117
+ // * supports `void operator()(absl::string_view) const`,
118
+ // * does not have alignment requirement greater than what is guaranteed by
119
+ // ::operator new. This is dictated by alignof(std::max_align_t) before
120
+ // C++17 and __STDCPP_DEFAULT_NEW_ALIGNMENT__ if compiling with C++17 or
121
+ // it is supported by the implementation.
122
+ //
123
+ // Example:
124
+ //
125
+ // Cord MakeCord(BlockPool* pool) {
126
+ // Block* block = pool->NewBlock();
127
+ // FillBlock(block);
128
+ // return absl::MakeCordFromExternal(
129
+ // block->ToStringView(),
130
+ // [pool, block](absl::string_view /*ignored*/) {
131
+ // pool->FreeBlock(block);
132
+ // });
133
+ // }
134
+ //
135
+ // WARNING: It's likely a bug if your releaser doesn't do anything.
136
+ // For example, consider the following:
137
+ //
138
+ // void Foo(const char* buffer, int len) {
139
+ // auto c = absl::MakeCordFromExternal(absl::string_view(buffer, len),
140
+ // [](absl::string_view) {});
141
+ //
142
+ // // BUG: If Bar() copies its cord for any reason, including keeping a
143
+ // // substring of it, the lifetime of buffer might be extended beyond
144
+ // // when Foo() returns.
145
+ // Bar(c);
146
+ // }
147
+ template <typename Releaser>
148
+ friend Cord MakeCordFromExternal(absl::string_view data, Releaser&& releaser);
149
+
150
+ // --------------------------------------------------------------------
151
+ // Mutations
152
+
153
+ void Clear();
154
+
155
+ void Append(const Cord& src);
156
+ void Append(Cord&& src);
157
+ void Append(absl::string_view src);
158
+ template <typename T, EnableIfString<T> = 0>
159
+ void Append(T&& src);
160
+
161
+ void Prepend(const Cord& src);
162
+ void Prepend(absl::string_view src);
163
+ template <typename T, EnableIfString<T> = 0>
164
+ void Prepend(T&& src);
165
+
166
+ void RemovePrefix(size_t n);
167
+ void RemoveSuffix(size_t n);
168
+
169
+ // Returns a new cord representing the subrange [pos, pos + new_size) of
170
+ // *this. If pos >= size(), the result is empty(). If
171
+ // (pos + new_size) >= size(), the result is the subrange [pos, size()).
172
+ Cord Subcord(size_t pos, size_t new_size) const;
173
+
174
+ friend void swap(Cord& x, Cord& y) noexcept;
175
+
176
+ // --------------------------------------------------------------------
177
+ // Accessors
178
+
179
+ size_t size() const;
180
+ bool empty() const;
181
+
182
+ // Returns the approximate number of bytes pinned by this Cord. Note that
183
+ // Cords that share memory could each be "charged" independently for the same
184
+ // shared memory.
185
+ size_t EstimatedMemoryUsage() const;
186
+
187
+ // --------------------------------------------------------------------
188
+ // Comparators
189
+
190
+ // Compares 'this' Cord with rhs. This function and its relatives
191
+ // treat Cords as sequences of unsigned bytes. The comparison is a
192
+ // straightforward lexicographic comparison. Return value:
193
+ // -1 'this' Cord is smaller
194
+ // 0 two Cords are equal
195
+ // 1 'this' Cord is larger
196
+ int Compare(absl::string_view rhs) const;
197
+ int Compare(const Cord& rhs) const;
198
+
199
+ // Does 'this' cord start/end with rhs
200
+ bool StartsWith(const Cord& rhs) const;
201
+ bool StartsWith(absl::string_view rhs) const;
202
+ bool EndsWith(absl::string_view rhs) const;
203
+ bool EndsWith(const Cord& rhs) const;
204
+
205
+ // --------------------------------------------------------------------
206
+ // Conversion to other types
207
+
208
+ explicit operator std::string() const;
209
+
210
+ // Copies the contents from `src` to `*dst`.
211
+ //
212
+ // This function optimizes the case of reusing the destination std::string since it
213
+ // can reuse previously allocated capacity. However, this function does not
214
+ // guarantee that pointers previously returned by `dst->data()` remain valid
215
+ // even if `*dst` had enough capacity to hold `src`. If `*dst` is a new
216
+ // object, prefer to simply use the conversion operator to `std::string`.
217
+ friend void CopyCordToString(const Cord& src, std::string* dst);
218
+
219
+ // --------------------------------------------------------------------
220
+ // Iteration
221
+
222
+ class CharIterator;
223
+
224
+ // Type for iterating over the chunks of a `Cord`. See comments for
225
+ // `Cord::chunk_begin()`, `Cord::chunk_end()` and `Cord::Chunks()` below for
226
+ // preferred usage.
227
+ //
228
+ // Additional notes:
229
+ // * The `string_view` returned by dereferencing a valid, non-`end()`
230
+ // iterator is guaranteed to be non-empty.
231
+ // * A `ChunkIterator` object is invalidated after any non-const
232
+ // operation on the `Cord` object over which it iterates.
233
+ // * Two `ChunkIterator` objects can be equality compared if and only if
234
+ // they remain valid and iterate over the same `Cord`.
235
+ // * This is a proxy iterator. This means the `string_view` returned by the
236
+ // iterator does not live inside the Cord, and its lifetime is limited to
237
+ // the lifetime of the iterator itself. To help prevent issues,
238
+ // `ChunkIterator::reference` is not a true reference type and is
239
+ // equivalent to `value_type`.
240
+ // * The iterator keeps state that can grow for `Cord`s that contain many
241
+ // nodes and are imbalanced due to sharing. Prefer to pass this type by
242
+ // const reference instead of by value.
243
+ class ChunkIterator {
244
+ public:
245
+ using iterator_category = std::input_iterator_tag;
246
+ using value_type = absl::string_view;
247
+ using difference_type = ptrdiff_t;
248
+ using pointer = const value_type*;
249
+ using reference = value_type;
250
+
251
+ ChunkIterator() = default;
252
+
253
+ ChunkIterator& operator++();
254
+ ChunkIterator operator++(int);
255
+ bool operator==(const ChunkIterator& other) const;
256
+ bool operator!=(const ChunkIterator& other) const;
257
+ reference operator*() const;
258
+ pointer operator->() const;
259
+
260
+ friend class Cord;
261
+ friend class CharIterator;
262
+
263
+ private:
264
+ // Constructs a `begin()` iterator from `cord`.
265
+ explicit ChunkIterator(const Cord* cord);
266
+
267
+ // Removes `n` bytes from `current_chunk_`. Expects `n` to be smaller than
268
+ // `current_chunk_.size()`.
269
+ void RemoveChunkPrefix(size_t n);
270
+ Cord AdvanceAndReadBytes(size_t n);
271
+ void AdvanceBytes(size_t n);
272
+ // Iterates `n` bytes, where `n` is expected to be greater than or equal to
273
+ // `current_chunk_.size()`.
274
+ void AdvanceBytesSlowPath(size_t n);
275
+
276
+ // A view into bytes of the current `CordRep`. It may only be a view to a
277
+ // suffix of bytes if this is being used by `CharIterator`.
278
+ absl::string_view current_chunk_;
279
+ // The current leaf, or `nullptr` if the iterator points to short data.
280
+ // If the current chunk is a substring node, current_leaf_ points to the
281
+ // underlying flat or external node.
282
+ absl::cord_internal::CordRep* current_leaf_ = nullptr;
283
+ // The number of bytes left in the `Cord` over which we are iterating.
284
+ size_t bytes_remaining_ = 0;
285
+ absl::InlinedVector<absl::cord_internal::CordRep*, 4>
286
+ stack_of_right_children_;
287
+ };
288
+
289
+ // Returns an iterator to the first chunk of the `Cord`.
290
+ //
291
+ // This is useful for getting a `ChunkIterator` outside the context of a
292
+ // range-based for-loop (in which case see `Cord::Chunks()` below).
293
+ //
294
+ // Example:
295
+ //
296
+ // absl::Cord::ChunkIterator FindAsChunk(const absl::Cord& c,
297
+ // absl::string_view s) {
298
+ // return std::find(c.chunk_begin(), c.chunk_end(), s);
299
+ // }
300
+ ChunkIterator chunk_begin() const;
301
+ // Returns an iterator one increment past the last chunk of the `Cord`.
302
+ ChunkIterator chunk_end() const;
303
+
304
+ // Convenience wrapper over `Cord::chunk_begin()` and `Cord::chunk_end()` to
305
+ // enable range-based for-loop iteration over `Cord` chunks.
306
+ //
307
+ // Prefer to use `Cord::Chunks()` below instead of constructing this directly.
308
+ class ChunkRange {
309
+ public:
310
+ explicit ChunkRange(const Cord* cord) : cord_(cord) {}
311
+
312
+ ChunkIterator begin() const;
313
+ ChunkIterator end() const;
314
+
315
+ private:
316
+ const Cord* cord_;
317
+ };
318
+
319
+ // Returns a range for iterating over the chunks of a `Cord` with a
320
+ // range-based for-loop.
321
+ //
322
+ // Example:
323
+ //
324
+ // void ProcessChunks(const Cord& cord) {
325
+ // for (absl::string_view chunk : cord.Chunks()) { ... }
326
+ // }
327
+ //
328
+ // Note that the ordinary caveats of temporary lifetime extension apply:
329
+ //
330
+ // void Process() {
331
+ // for (absl::string_view chunk : CordFactory().Chunks()) {
332
+ // // The temporary Cord returned by CordFactory has been destroyed!
333
+ // }
334
+ // }
335
+ ChunkRange Chunks() const;
336
+
337
+ // Type for iterating over the characters of a `Cord`. See comments for
338
+ // `Cord::char_begin()`, `Cord::char_end()` and `Cord::Chars()` below for
339
+ // preferred usage.
340
+ //
341
+ // Additional notes:
342
+ // * A `CharIterator` object is invalidated after any non-const
343
+ // operation on the `Cord` object over which it iterates.
344
+ // * Two `CharIterator` objects can be equality compared if and only if
345
+ // they remain valid and iterate over the same `Cord`.
346
+ // * The iterator keeps state that can grow for `Cord`s that contain many
347
+ // nodes and are imbalanced due to sharing. Prefer to pass this type by
348
+ // const reference instead of by value.
349
+ // * This type cannot be a forward iterator because a `Cord` can reuse
350
+ // sections of memory. This violates the requirement that if dereferencing
351
+ // two iterators returns the same object, the iterators must compare
352
+ // equal.
353
+ class CharIterator {
354
+ public:
355
+ using iterator_category = std::input_iterator_tag;
356
+ using value_type = char;
357
+ using difference_type = ptrdiff_t;
358
+ using pointer = const char*;
359
+ using reference = const char&;
360
+
361
+ CharIterator() = default;
362
+
363
+ CharIterator& operator++();
364
+ CharIterator operator++(int);
365
+ bool operator==(const CharIterator& other) const;
366
+ bool operator!=(const CharIterator& other) const;
367
+ reference operator*() const;
368
+ pointer operator->() const;
369
+
370
+ friend Cord;
371
+
372
+ private:
373
+ explicit CharIterator(const Cord* cord) : chunk_iterator_(cord) {}
374
+
375
+ ChunkIterator chunk_iterator_;
376
+ };
377
+
378
+ // Advances `*it` by `n_bytes` and returns the bytes passed as a `Cord`.
379
+ //
380
+ // `n_bytes` must be less than or equal to the number of bytes remaining for
381
+ // iteration. Otherwise the behavior is undefined. It is valid to pass
382
+ // `char_end()` and 0.
383
+ static Cord AdvanceAndRead(CharIterator* it, size_t n_bytes);
384
+
385
+ // Advances `*it` by `n_bytes`.
386
+ //
387
+ // `n_bytes` must be less than or equal to the number of bytes remaining for
388
+ // iteration. Otherwise the behavior is undefined. It is valid to pass
389
+ // `char_end()` and 0.
390
+ static void Advance(CharIterator* it, size_t n_bytes);
391
+
392
+ // Returns the longest contiguous view starting at the iterator's position.
393
+ //
394
+ // `it` must be dereferenceable.
395
+ static absl::string_view ChunkRemaining(const CharIterator& it);
396
+
397
+ // Returns an iterator to the first character of the `Cord`.
398
+ CharIterator char_begin() const;
399
+ // Returns an iterator to one past the last character of the `Cord`.
400
+ CharIterator char_end() const;
401
+
402
+ // Convenience wrapper over `Cord::char_begin()` and `Cord::char_end()` to
403
+ // enable range-based for-loop iterator over the characters of a `Cord`.
404
+ //
405
+ // Prefer to use `Cord::Chars()` below instead of constructing this directly.
406
+ class CharRange {
407
+ public:
408
+ explicit CharRange(const Cord* cord) : cord_(cord) {}
409
+
410
+ CharIterator begin() const;
411
+ CharIterator end() const;
412
+
413
+ private:
414
+ const Cord* cord_;
415
+ };
416
+
417
+ // Returns a range for iterating over the characters of a `Cord` with a
418
+ // range-based for-loop.
419
+ //
420
+ // Example:
421
+ //
422
+ // void ProcessCord(const Cord& cord) {
423
+ // for (char c : cord.Chars()) { ... }
424
+ // }
425
+ //
426
+ // Note that the ordinary caveats of temporary lifetime extension apply:
427
+ //
428
+ // void Process() {
429
+ // for (char c : CordFactory().Chars()) {
430
+ // // The temporary Cord returned by CordFactory has been destroyed!
431
+ // }
432
+ // }
433
+ CharRange Chars() const;
434
+
435
+ // --------------------------------------------------------------------
436
+ // Miscellaneous
437
+
438
+ // Get the "i"th character of 'this' and return it.
439
+ // NOTE: This routine is reasonably efficient. It is roughly
440
+ // logarithmic in the number of nodes that make up the cord. Still,
441
+ // if you need to iterate over the contents of a cord, you should
442
+ // use a CharIterator/CordIterator rather than call operator[] or Get()
443
+ // repeatedly in a loop.
444
+ //
445
+ // REQUIRES: 0 <= i < size()
446
+ char operator[](size_t i) const;
447
+
448
+ // Flattens the cord into a single array and returns a view of the data.
449
+ //
450
+ // If the cord was already flat, the contents are not modified.
451
+ absl::string_view Flatten();
452
+
453
+ private:
454
+ friend class CordTestPeer;
455
+ template <typename H>
456
+ friend H absl::hash_internal::HashFragmentedCord(H, const Cord&);
457
+ friend bool operator==(const Cord& lhs, const Cord& rhs);
458
+ friend bool operator==(const Cord& lhs, absl::string_view rhs);
459
+
460
+ // Call the provided function once for each cord chunk, in order. Unlike
461
+ // Chunks(), this API will not allocate memory.
462
+ void ForEachChunk(absl::FunctionRef<void(absl::string_view)>) const;
463
+
464
+ // Allocates new contiguous storage for the contents of the cord. This is
465
+ // called by Flatten() when the cord was not already flat.
466
+ absl::string_view FlattenSlowPath();
467
+
468
+ // Actual cord contents are hidden inside the following simple
469
+ // class so that we can isolate the bulk of cord.cc from changes
470
+ // to the representation.
471
+ //
472
+ // InlineRep holds either either a tree pointer, or an array of kMaxInline
473
+ // bytes.
474
+ class InlineRep {
475
+ public:
476
+ static const unsigned char kMaxInline = 15;
477
+ static_assert(kMaxInline >= sizeof(absl::cord_internal::CordRep*), "");
478
+ // Tag byte & kMaxInline means we are storing a pointer.
479
+ static const unsigned char kTreeFlag = 1 << 4;
480
+ // Tag byte & kProfiledFlag means we are profiling the Cord.
481
+ static const unsigned char kProfiledFlag = 1 << 5;
482
+
483
+ constexpr InlineRep() : data_{} {}
484
+ InlineRep(const InlineRep& src);
485
+ InlineRep(InlineRep&& src);
486
+ InlineRep& operator=(const InlineRep& src);
487
+ InlineRep& operator=(InlineRep&& src) noexcept;
488
+
489
+ void Swap(InlineRep* rhs);
490
+ bool empty() const;
491
+ size_t size() const;
492
+ const char* data() const; // Returns nullptr if holding pointer
493
+ void set_data(const char* data, size_t n,
494
+ bool nullify_tail); // Discards pointer, if any
495
+ char* set_data(size_t n); // Write data to the result
496
+ // Returns nullptr if holding bytes
497
+ absl::cord_internal::CordRep* tree() const;
498
+ // Discards old pointer, if any
499
+ void set_tree(absl::cord_internal::CordRep* rep);
500
+ // Replaces a tree with a new root. This is faster than set_tree, but it
501
+ // should only be used when it's clear that the old rep was a tree.
502
+ void replace_tree(absl::cord_internal::CordRep* rep);
503
+ // Returns non-null iff was holding a pointer
504
+ absl::cord_internal::CordRep* clear();
505
+ // Convert to pointer if necessary
506
+ absl::cord_internal::CordRep* force_tree(size_t extra_hint);
507
+ void reduce_size(size_t n); // REQUIRES: holding data
508
+ void remove_prefix(size_t n); // REQUIRES: holding data
509
+ void AppendArray(const char* src_data, size_t src_size);
510
+ absl::string_view FindFlatStartPiece() const;
511
+ void AppendTree(absl::cord_internal::CordRep* tree);
512
+ void PrependTree(absl::cord_internal::CordRep* tree);
513
+ void GetAppendRegion(char** region, size_t* size, size_t max_length);
514
+ void GetAppendRegion(char** region, size_t* size);
515
+ bool IsSame(const InlineRep& other) const {
516
+ return memcmp(data_, other.data_, sizeof(data_)) == 0;
517
+ }
518
+ int BitwiseCompare(const InlineRep& other) const {
519
+ uint64_t x, y;
520
+ // Use memcpy to avoid anti-aliasing issues.
521
+ memcpy(&x, data_, sizeof(x));
522
+ memcpy(&y, other.data_, sizeof(y));
523
+ if (x == y) {
524
+ memcpy(&x, data_ + 8, sizeof(x));
525
+ memcpy(&y, other.data_ + 8, sizeof(y));
526
+ if (x == y) return 0;
527
+ }
528
+ return absl::big_endian::FromHost64(x) < absl::big_endian::FromHost64(y)
529
+ ? -1
530
+ : 1;
531
+ }
532
+ void CopyTo(std::string* dst) const {
533
+ // memcpy is much faster when operating on a known size. On most supported
534
+ // platforms, the small std::string optimization is large enough that resizing
535
+ // to 15 bytes does not cause a memory allocation.
536
+ absl::strings_internal::STLStringResizeUninitialized(dst,
537
+ sizeof(data_) - 1);
538
+ memcpy(&(*dst)[0], data_, sizeof(data_) - 1);
539
+ // erase is faster than resize because the logic for memory allocation is
540
+ // not needed.
541
+ dst->erase(data_[kMaxInline]);
542
+ }
543
+
544
+ // Copies the inline contents into `dst`. Assumes the cord is not empty.
545
+ void CopyToArray(char* dst) const;
546
+
547
+ bool is_tree() const { return data_[kMaxInline] > kMaxInline; }
548
+
549
+ private:
550
+ friend class Cord;
551
+
552
+ void AssignSlow(const InlineRep& src);
553
+ // Unrefs the tree, stops profiling, and zeroes the contents
554
+ void ClearSlow();
555
+
556
+ // If the data has length <= kMaxInline, we store it in data_[0..len-1],
557
+ // and store the length in data_[kMaxInline]. Else we store it in a tree
558
+ // and store a pointer to that tree in data_[0..sizeof(CordRep*)-1].
559
+ alignas(absl::cord_internal::CordRep*) char data_[kMaxInline + 1];
560
+ };
561
+ InlineRep contents_;
562
+
563
+ // Helper for MemoryUsage()
564
+ static size_t MemoryUsageAux(const absl::cord_internal::CordRep* rep);
565
+
566
+ // Helper for GetFlat()
567
+ static bool GetFlatAux(absl::cord_internal::CordRep* rep,
568
+ absl::string_view* fragment);
569
+
570
+ // Helper for ForEachChunk()
571
+ static void ForEachChunkAux(
572
+ absl::cord_internal::CordRep* rep,
573
+ absl::FunctionRef<void(absl::string_view)> callback);
574
+
575
+ // The destructor for non-empty Cords.
576
+ void DestroyCordSlow();
577
+
578
+ // Out-of-line implementation of slower parts of logic.
579
+ void CopyToArraySlowPath(char* dst) const;
580
+ int CompareSlowPath(absl::string_view rhs, size_t compared_size,
581
+ size_t size_to_compare) const;
582
+ int CompareSlowPath(const Cord& rhs, size_t compared_size,
583
+ size_t size_to_compare) const;
584
+ bool EqualsImpl(absl::string_view rhs, size_t size_to_compare) const;
585
+ bool EqualsImpl(const Cord& rhs, size_t size_to_compare) const;
586
+ int CompareImpl(const Cord& rhs) const;
587
+
588
+ template <typename ResultType, typename RHS>
589
+ friend ResultType GenericCompare(const Cord& lhs, const RHS& rhs,
590
+ size_t size_to_compare);
591
+ static absl::string_view GetFirstChunk(const Cord& c);
592
+ static absl::string_view GetFirstChunk(absl::string_view sv);
593
+
594
+ // Returns a new reference to contents_.tree(), or steals an existing
595
+ // reference if called on an rvalue.
596
+ absl::cord_internal::CordRep* TakeRep() const&;
597
+ absl::cord_internal::CordRep* TakeRep() &&;
598
+
599
+ // Helper for Append()
600
+ template <typename C>
601
+ void AppendImpl(C&& src);
602
+ };
603
+
604
+ ABSL_NAMESPACE_END
605
+ } // namespace absl
606
+
607
+ namespace absl {
608
+ ABSL_NAMESPACE_BEGIN
609
+
610
+ // allow a Cord to be logged
611
+ extern std::ostream& operator<<(std::ostream& out, const Cord& cord);
612
+
613
+ // ------------------------------------------------------------------
614
+ // Internal details follow. Clients should ignore.
615
+
616
+ namespace cord_internal {
617
+
618
+ // Fast implementation of memmove for up to 15 bytes. This implementation is
619
+ // safe for overlapping regions. If nullify_tail is true, the destination is
620
+ // padded with '\0' up to 16 bytes.
621
+ inline void SmallMemmove(char* dst, const char* src, size_t n,
622
+ bool nullify_tail = false) {
623
+ if (n >= 8) {
624
+ assert(n <= 16);
625
+ uint64_t buf1;
626
+ uint64_t buf2;
627
+ memcpy(&buf1, src, 8);
628
+ memcpy(&buf2, src + n - 8, 8);
629
+ if (nullify_tail) {
630
+ memset(dst + 8, 0, 8);
631
+ }
632
+ memcpy(dst, &buf1, 8);
633
+ memcpy(dst + n - 8, &buf2, 8);
634
+ } else if (n >= 4) {
635
+ uint32_t buf1;
636
+ uint32_t buf2;
637
+ memcpy(&buf1, src, 4);
638
+ memcpy(&buf2, src + n - 4, 4);
639
+ if (nullify_tail) {
640
+ memset(dst + 4, 0, 4);
641
+ memset(dst + 8, 0, 8);
642
+ }
643
+ memcpy(dst, &buf1, 4);
644
+ memcpy(dst + n - 4, &buf2, 4);
645
+ } else {
646
+ if (n != 0) {
647
+ dst[0] = src[0];
648
+ dst[n / 2] = src[n / 2];
649
+ dst[n - 1] = src[n - 1];
650
+ }
651
+ if (nullify_tail) {
652
+ memset(dst + 8, 0, 8);
653
+ memset(dst + n, 0, 8);
654
+ }
655
+ }
656
+ }
657
+
658
+ struct ExternalRepReleaserPair {
659
+ CordRep* rep;
660
+ void* releaser_address;
661
+ };
662
+
663
+ // Allocates a new external `CordRep` and returns a pointer to it and a pointer
664
+ // to `releaser_size` bytes where the desired releaser can be constructed.
665
+ // Expects `data` to be non-empty.
666
+ ExternalRepReleaserPair NewExternalWithUninitializedReleaser(
667
+ absl::string_view data, ExternalReleaserInvoker invoker,
668
+ size_t releaser_size);
669
+
670
+ // Creates a new `CordRep` that owns `data` and `releaser` and returns a pointer
671
+ // to it, or `nullptr` if `data` was empty.
672
+ template <typename Releaser>
673
+ // NOLINTNEXTLINE - suppress clang-tidy raw pointer return.
674
+ CordRep* NewExternalRep(absl::string_view data, Releaser&& releaser) {
675
+ static_assert(
676
+ #if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
677
+ alignof(Releaser) <= __STDCPP_DEFAULT_NEW_ALIGNMENT__,
678
+ #else
679
+ alignof(Releaser) <= alignof(max_align_t),
680
+ #endif
681
+ "Releasers with alignment requirement greater than what is returned by "
682
+ "default `::operator new()` are not supported.");
683
+
684
+ using ReleaserType = absl::decay_t<Releaser>;
685
+ if (data.empty()) {
686
+ // Never create empty external nodes.
687
+ ::absl::base_internal::Invoke(
688
+ ReleaserType(std::forward<Releaser>(releaser)), data);
689
+ return nullptr;
690
+ }
691
+
692
+ auto releaser_invoker = [](void* type_erased_releaser, absl::string_view d) {
693
+ auto* my_releaser = static_cast<ReleaserType*>(type_erased_releaser);
694
+ ::absl::base_internal::Invoke(std::move(*my_releaser), d);
695
+ my_releaser->~ReleaserType();
696
+ return sizeof(Releaser);
697
+ };
698
+
699
+ ExternalRepReleaserPair external = NewExternalWithUninitializedReleaser(
700
+ data, releaser_invoker, sizeof(releaser));
701
+ ::new (external.releaser_address)
702
+ ReleaserType(std::forward<Releaser>(releaser));
703
+ return external.rep;
704
+ }
705
+
706
+ // Overload for function reference types that dispatches using a function
707
+ // pointer because there are no `alignof()` or `sizeof()` a function reference.
708
+ // NOLINTNEXTLINE - suppress clang-tidy raw pointer return.
709
+ inline CordRep* NewExternalRep(absl::string_view data,
710
+ void (&releaser)(absl::string_view)) {
711
+ return NewExternalRep(data, &releaser);
712
+ }
713
+
714
+ } // namespace cord_internal
715
+
716
+ template <typename Releaser>
717
+ Cord MakeCordFromExternal(absl::string_view data, Releaser&& releaser) {
718
+ Cord cord;
719
+ cord.contents_.set_tree(::absl::cord_internal::NewExternalRep(
720
+ data, std::forward<Releaser>(releaser)));
721
+ return cord;
722
+ }
723
+
724
+ inline Cord::InlineRep::InlineRep(const Cord::InlineRep& src) {
725
+ cord_internal::SmallMemmove(data_, src.data_, sizeof(data_));
726
+ }
727
+
728
+ inline Cord::InlineRep::InlineRep(Cord::InlineRep&& src) {
729
+ memcpy(data_, src.data_, sizeof(data_));
730
+ memset(src.data_, 0, sizeof(data_));
731
+ }
732
+
733
+ inline Cord::InlineRep& Cord::InlineRep::operator=(const Cord::InlineRep& src) {
734
+ if (this == &src) {
735
+ return *this;
736
+ }
737
+ if (!is_tree() && !src.is_tree()) {
738
+ cord_internal::SmallMemmove(data_, src.data_, sizeof(data_));
739
+ return *this;
740
+ }
741
+ AssignSlow(src);
742
+ return *this;
743
+ }
744
+
745
+ inline Cord::InlineRep& Cord::InlineRep::operator=(
746
+ Cord::InlineRep&& src) noexcept {
747
+ if (is_tree()) {
748
+ ClearSlow();
749
+ }
750
+ memcpy(data_, src.data_, sizeof(data_));
751
+ memset(src.data_, 0, sizeof(data_));
752
+ return *this;
753
+ }
754
+
755
+ inline void Cord::InlineRep::Swap(Cord::InlineRep* rhs) {
756
+ if (rhs == this) {
757
+ return;
758
+ }
759
+
760
+ Cord::InlineRep tmp;
761
+ cord_internal::SmallMemmove(tmp.data_, data_, sizeof(data_));
762
+ cord_internal::SmallMemmove(data_, rhs->data_, sizeof(data_));
763
+ cord_internal::SmallMemmove(rhs->data_, tmp.data_, sizeof(data_));
764
+ }
765
+
766
+ inline const char* Cord::InlineRep::data() const {
767
+ return is_tree() ? nullptr : data_;
768
+ }
769
+
770
+ inline absl::cord_internal::CordRep* Cord::InlineRep::tree() const {
771
+ if (is_tree()) {
772
+ absl::cord_internal::CordRep* rep;
773
+ memcpy(&rep, data_, sizeof(rep));
774
+ return rep;
775
+ } else {
776
+ return nullptr;
777
+ }
778
+ }
779
+
780
+ inline bool Cord::InlineRep::empty() const { return data_[kMaxInline] == 0; }
781
+
782
+ inline size_t Cord::InlineRep::size() const {
783
+ const char tag = data_[kMaxInline];
784
+ if (tag <= kMaxInline) return tag;
785
+ return static_cast<size_t>(tree()->length);
786
+ }
787
+
788
+ inline void Cord::InlineRep::set_tree(absl::cord_internal::CordRep* rep) {
789
+ if (rep == nullptr) {
790
+ memset(data_, 0, sizeof(data_));
791
+ } else {
792
+ bool was_tree = is_tree();
793
+ memcpy(data_, &rep, sizeof(rep));
794
+ memset(data_ + sizeof(rep), 0, sizeof(data_) - sizeof(rep) - 1);
795
+ if (!was_tree) {
796
+ data_[kMaxInline] = kTreeFlag;
797
+ }
798
+ }
799
+ }
800
+
801
+ inline void Cord::InlineRep::replace_tree(absl::cord_internal::CordRep* rep) {
802
+ ABSL_ASSERT(is_tree());
803
+ if (ABSL_PREDICT_FALSE(rep == nullptr)) {
804
+ set_tree(rep);
805
+ return;
806
+ }
807
+ memcpy(data_, &rep, sizeof(rep));
808
+ memset(data_ + sizeof(rep), 0, sizeof(data_) - sizeof(rep) - 1);
809
+ }
810
+
811
+ inline absl::cord_internal::CordRep* Cord::InlineRep::clear() {
812
+ const char tag = data_[kMaxInline];
813
+ absl::cord_internal::CordRep* result = nullptr;
814
+ if (tag > kMaxInline) {
815
+ memcpy(&result, data_, sizeof(result));
816
+ }
817
+ memset(data_, 0, sizeof(data_)); // Clear the cord
818
+ return result;
819
+ }
820
+
821
+ inline void Cord::InlineRep::CopyToArray(char* dst) const {
822
+ assert(!is_tree());
823
+ size_t n = data_[kMaxInline];
824
+ assert(n != 0);
825
+ cord_internal::SmallMemmove(dst, data_, n);
826
+ }
827
+
828
+ constexpr inline Cord::Cord() noexcept {}
829
+
830
+ inline Cord& Cord::operator=(const Cord& x) {
831
+ contents_ = x.contents_;
832
+ return *this;
833
+ }
834
+
835
+ inline Cord::Cord(Cord&& src) noexcept : contents_(std::move(src.contents_)) {}
836
+
837
+ inline Cord& Cord::operator=(Cord&& x) noexcept {
838
+ contents_ = std::move(x.contents_);
839
+ return *this;
840
+ }
841
+
842
+ template <typename T, Cord::EnableIfString<T>>
843
+ inline Cord& Cord::operator=(T&& src) {
844
+ *this = absl::string_view(src);
845
+ return *this;
846
+ }
847
+
848
+ inline size_t Cord::size() const {
849
+ // Length is 1st field in str.rep_
850
+ return contents_.size();
851
+ }
852
+
853
+ inline bool Cord::empty() const { return contents_.empty(); }
854
+
855
+ inline size_t Cord::EstimatedMemoryUsage() const {
856
+ size_t result = sizeof(Cord);
857
+ if (const absl::cord_internal::CordRep* rep = contents_.tree()) {
858
+ result += MemoryUsageAux(rep);
859
+ }
860
+ return result;
861
+ }
862
+
863
+ inline absl::string_view Cord::Flatten() {
864
+ absl::cord_internal::CordRep* rep = contents_.tree();
865
+ if (rep == nullptr) {
866
+ return absl::string_view(contents_.data(), contents_.size());
867
+ } else {
868
+ absl::string_view already_flat_contents;
869
+ if (GetFlatAux(rep, &already_flat_contents)) {
870
+ return already_flat_contents;
871
+ }
872
+ }
873
+ return FlattenSlowPath();
874
+ }
875
+
876
+ inline void Cord::Append(absl::string_view src) {
877
+ contents_.AppendArray(src.data(), src.size());
878
+ }
879
+
880
+ template <typename T, Cord::EnableIfString<T>>
881
+ inline void Cord::Append(T&& src) {
882
+ // Note that this function reserves the right to reuse the `string&&`'s
883
+ // memory and that it will do so in the future.
884
+ Append(absl::string_view(src));
885
+ }
886
+
887
+ template <typename T, Cord::EnableIfString<T>>
888
+ inline void Cord::Prepend(T&& src) {
889
+ // Note that this function reserves the right to reuse the `string&&`'s
890
+ // memory and that it will do so in the future.
891
+ Prepend(absl::string_view(src));
892
+ }
893
+
894
+ inline int Cord::Compare(const Cord& rhs) const {
895
+ if (!contents_.is_tree() && !rhs.contents_.is_tree()) {
896
+ return contents_.BitwiseCompare(rhs.contents_);
897
+ }
898
+
899
+ return CompareImpl(rhs);
900
+ }
901
+
902
+ // Does 'this' cord start/end with rhs
903
+ inline bool Cord::StartsWith(const Cord& rhs) const {
904
+ if (contents_.IsSame(rhs.contents_)) return true;
905
+ size_t rhs_size = rhs.size();
906
+ if (size() < rhs_size) return false;
907
+ return EqualsImpl(rhs, rhs_size);
908
+ }
909
+
910
+ inline bool Cord::StartsWith(absl::string_view rhs) const {
911
+ size_t rhs_size = rhs.size();
912
+ if (size() < rhs_size) return false;
913
+ return EqualsImpl(rhs, rhs_size);
914
+ }
915
+
916
+ inline Cord::ChunkIterator::ChunkIterator(const Cord* cord)
917
+ : bytes_remaining_(cord->size()) {
918
+ if (cord->empty()) return;
919
+ if (cord->contents_.is_tree()) {
920
+ stack_of_right_children_.push_back(cord->contents_.tree());
921
+ operator++();
922
+ } else {
923
+ current_chunk_ = absl::string_view(cord->contents_.data(), cord->size());
924
+ }
925
+ }
926
+
927
+ inline Cord::ChunkIterator Cord::ChunkIterator::operator++(int) {
928
+ ChunkIterator tmp(*this);
929
+ operator++();
930
+ return tmp;
931
+ }
932
+
933
+ inline bool Cord::ChunkIterator::operator==(const ChunkIterator& other) const {
934
+ return bytes_remaining_ == other.bytes_remaining_;
935
+ }
936
+
937
+ inline bool Cord::ChunkIterator::operator!=(const ChunkIterator& other) const {
938
+ return !(*this == other);
939
+ }
940
+
941
+ inline Cord::ChunkIterator::reference Cord::ChunkIterator::operator*() const {
942
+ assert(bytes_remaining_ != 0);
943
+ return current_chunk_;
944
+ }
945
+
946
+ inline Cord::ChunkIterator::pointer Cord::ChunkIterator::operator->() const {
947
+ assert(bytes_remaining_ != 0);
948
+ return &current_chunk_;
949
+ }
950
+
951
+ inline void Cord::ChunkIterator::RemoveChunkPrefix(size_t n) {
952
+ assert(n < current_chunk_.size());
953
+ current_chunk_.remove_prefix(n);
954
+ bytes_remaining_ -= n;
955
+ }
956
+
957
+ inline void Cord::ChunkIterator::AdvanceBytes(size_t n) {
958
+ if (ABSL_PREDICT_TRUE(n < current_chunk_.size())) {
959
+ RemoveChunkPrefix(n);
960
+ } else if (n != 0) {
961
+ AdvanceBytesSlowPath(n);
962
+ }
963
+ }
964
+
965
+ inline Cord::ChunkIterator Cord::chunk_begin() const {
966
+ return ChunkIterator(this);
967
+ }
968
+
969
+ inline Cord::ChunkIterator Cord::chunk_end() const { return ChunkIterator(); }
970
+
971
+ inline Cord::ChunkIterator Cord::ChunkRange::begin() const {
972
+ return cord_->chunk_begin();
973
+ }
974
+
975
+ inline Cord::ChunkIterator Cord::ChunkRange::end() const {
976
+ return cord_->chunk_end();
977
+ }
978
+
979
+ inline Cord::ChunkRange Cord::Chunks() const { return ChunkRange(this); }
980
+
981
+ inline Cord::CharIterator& Cord::CharIterator::operator++() {
982
+ if (ABSL_PREDICT_TRUE(chunk_iterator_->size() > 1)) {
983
+ chunk_iterator_.RemoveChunkPrefix(1);
984
+ } else {
985
+ ++chunk_iterator_;
986
+ }
987
+ return *this;
988
+ }
989
+
990
+ inline Cord::CharIterator Cord::CharIterator::operator++(int) {
991
+ CharIterator tmp(*this);
992
+ operator++();
993
+ return tmp;
994
+ }
995
+
996
+ inline bool Cord::CharIterator::operator==(const CharIterator& other) const {
997
+ return chunk_iterator_ == other.chunk_iterator_;
998
+ }
999
+
1000
+ inline bool Cord::CharIterator::operator!=(const CharIterator& other) const {
1001
+ return !(*this == other);
1002
+ }
1003
+
1004
+ inline Cord::CharIterator::reference Cord::CharIterator::operator*() const {
1005
+ return *chunk_iterator_->data();
1006
+ }
1007
+
1008
+ inline Cord::CharIterator::pointer Cord::CharIterator::operator->() const {
1009
+ return chunk_iterator_->data();
1010
+ }
1011
+
1012
+ inline Cord Cord::AdvanceAndRead(CharIterator* it, size_t n_bytes) {
1013
+ assert(it != nullptr);
1014
+ return it->chunk_iterator_.AdvanceAndReadBytes(n_bytes);
1015
+ }
1016
+
1017
+ inline void Cord::Advance(CharIterator* it, size_t n_bytes) {
1018
+ assert(it != nullptr);
1019
+ it->chunk_iterator_.AdvanceBytes(n_bytes);
1020
+ }
1021
+
1022
+ inline absl::string_view Cord::ChunkRemaining(const CharIterator& it) {
1023
+ return *it.chunk_iterator_;
1024
+ }
1025
+
1026
+ inline Cord::CharIterator Cord::char_begin() const {
1027
+ return CharIterator(this);
1028
+ }
1029
+
1030
+ inline Cord::CharIterator Cord::char_end() const { return CharIterator(); }
1031
+
1032
+ inline Cord::CharIterator Cord::CharRange::begin() const {
1033
+ return cord_->char_begin();
1034
+ }
1035
+
1036
+ inline Cord::CharIterator Cord::CharRange::end() const {
1037
+ return cord_->char_end();
1038
+ }
1039
+
1040
+ inline Cord::CharRange Cord::Chars() const { return CharRange(this); }
1041
+
1042
+ inline void Cord::ForEachChunk(
1043
+ absl::FunctionRef<void(absl::string_view)> callback) const {
1044
+ absl::cord_internal::CordRep* rep = contents_.tree();
1045
+ if (rep == nullptr) {
1046
+ callback(absl::string_view(contents_.data(), contents_.size()));
1047
+ } else {
1048
+ return ForEachChunkAux(rep, callback);
1049
+ }
1050
+ }
1051
+
1052
+ // Nonmember Cord-to-Cord relational operarators.
1053
+ inline bool operator==(const Cord& lhs, const Cord& rhs) {
1054
+ if (lhs.contents_.IsSame(rhs.contents_)) return true;
1055
+ size_t rhs_size = rhs.size();
1056
+ if (lhs.size() != rhs_size) return false;
1057
+ return lhs.EqualsImpl(rhs, rhs_size);
1058
+ }
1059
+
1060
+ inline bool operator!=(const Cord& x, const Cord& y) { return !(x == y); }
1061
+ inline bool operator<(const Cord& x, const Cord& y) {
1062
+ return x.Compare(y) < 0;
1063
+ }
1064
+ inline bool operator>(const Cord& x, const Cord& y) {
1065
+ return x.Compare(y) > 0;
1066
+ }
1067
+ inline bool operator<=(const Cord& x, const Cord& y) {
1068
+ return x.Compare(y) <= 0;
1069
+ }
1070
+ inline bool operator>=(const Cord& x, const Cord& y) {
1071
+ return x.Compare(y) >= 0;
1072
+ }
1073
+
1074
+ // Nonmember Cord-to-absl::string_view relational operators.
1075
+ //
1076
+ // Due to implicit conversions, these also enable comparisons of Cord with
1077
+ // with std::string, ::string, and const char*.
1078
+ inline bool operator==(const Cord& lhs, absl::string_view rhs) {
1079
+ size_t lhs_size = lhs.size();
1080
+ size_t rhs_size = rhs.size();
1081
+ if (lhs_size != rhs_size) return false;
1082
+ return lhs.EqualsImpl(rhs, rhs_size);
1083
+ }
1084
+
1085
+ inline bool operator==(absl::string_view x, const Cord& y) { return y == x; }
1086
+ inline bool operator!=(const Cord& x, absl::string_view y) { return !(x == y); }
1087
+ inline bool operator!=(absl::string_view x, const Cord& y) { return !(x == y); }
1088
+ inline bool operator<(const Cord& x, absl::string_view y) {
1089
+ return x.Compare(y) < 0;
1090
+ }
1091
+ inline bool operator<(absl::string_view x, const Cord& y) {
1092
+ return y.Compare(x) > 0;
1093
+ }
1094
+ inline bool operator>(const Cord& x, absl::string_view y) { return y < x; }
1095
+ inline bool operator>(absl::string_view x, const Cord& y) { return y < x; }
1096
+ inline bool operator<=(const Cord& x, absl::string_view y) { return !(y < x); }
1097
+ inline bool operator<=(absl::string_view x, const Cord& y) { return !(y < x); }
1098
+ inline bool operator>=(const Cord& x, absl::string_view y) { return !(x < y); }
1099
+ inline bool operator>=(absl::string_view x, const Cord& y) { return !(x < y); }
1100
+
1101
+ // Overload of swap for Cord. The use of non-const references is
1102
+ // required. :(
1103
+ inline void swap(Cord& x, Cord& y) noexcept { y.contents_.Swap(&x.contents_); }
1104
+
1105
+ // Some internals exposed to test code.
1106
+ namespace strings_internal {
1107
+ class CordTestAccess {
1108
+ public:
1109
+ static size_t FlatOverhead();
1110
+ static size_t MaxFlatLength();
1111
+ static size_t SizeofCordRepConcat();
1112
+ static size_t SizeofCordRepExternal();
1113
+ static size_t SizeofCordRepSubstring();
1114
+ static size_t FlatTagToLength(uint8_t tag);
1115
+ static uint8_t LengthToTag(size_t s);
1116
+ };
1117
+ } // namespace strings_internal
1118
+ ABSL_NAMESPACE_END
1119
+ } // namespace absl
1120
+
1121
+ #endif // ABSL_STRINGS_CORD_H_