grpc 1.33.0.pre1 → 1.34.0
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.
- checksums.yaml +4 -4
- data/Makefile +342 -134
- data/include/grpc/grpc.h +1 -2
- data/include/grpc/grpc_security.h +149 -172
- data/include/grpc/impl/codegen/grpc_types.h +9 -2
- data/include/grpc/impl/codegen/port_platform.h +22 -55
- data/src/core/ext/filters/client_channel/client_channel.cc +11 -34
- data/src/core/ext/filters/client_channel/config_selector.h +2 -3
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +4 -1
- data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -2
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.cc +5 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +3 -3
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +80 -71
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +3 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +2 -2
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +47 -17
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +2 -2
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +8 -5
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +3 -3
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +16 -243
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +53 -17
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +809 -0
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +20 -25
- data/src/core/ext/filters/client_channel/resolver.cc +3 -1
- data/src/core/ext/filters/client_channel/resolver.h +4 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +20 -0
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +66 -7
- data/src/core/ext/filters/client_channel/resolver_registry.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +13 -25
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +2 -2
- data/src/core/ext/filters/client_channel/retry_throttle.h +1 -1
- data/src/core/ext/filters/client_channel/server_address.h +0 -4
- data/src/core/ext/filters/client_channel/service_config.cc +3 -1
- data/src/core/ext/filters/client_channel/service_config.h +1 -1
- data/src/core/ext/filters/client_channel/subchannel.cc +18 -15
- data/src/core/ext/filters/client_channel/subchannel.h +2 -2
- data/src/core/ext/filters/client_channel/subchannel_interface.h +7 -15
- data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +6 -2
- data/src/core/ext/filters/deadline/deadline_filter.cc +83 -77
- data/src/core/ext/filters/deadline/deadline_filter.h +7 -11
- data/src/core/ext/filters/http/client/http_client_filter.cc +1 -1
- data/src/core/ext/filters/http/server/http_server_filter.cc +3 -3
- data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +17 -3
- data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +7 -7
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +4 -24
- data/src/core/ext/transport/chttp2/transport/flow_control.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +12 -8
- data/src/core/ext/transport/chttp2/transport/internal.h +0 -1
- data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/writing.cc +1 -2
- data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +38 -0
- data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.c +41 -0
- data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +254 -0
- data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.h +105 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.c +100 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +558 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.h +145 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.c +53 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.c +133 -0
- data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.c +127 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.h +65 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.c +56 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +266 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +125 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +143 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.c +56 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.c +66 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.c +263 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.h +100 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +233 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.h +70 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.c +56 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +228 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +80 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.c +46 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.c +59 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +55 -0
- data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.c +110 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.h +50 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +113 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.h +50 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.c +146 -0
- data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.c +50 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +190 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +185 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.h +65 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +62 -0
- data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +97 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +915 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +280 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.c +71 -0
- data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.c +64 -0
- data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +511 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +115 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.c +48 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +166 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c +105 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +249 -0
- data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h +60 -0
- data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.c +72 -0
- data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.c +60 -0
- data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.c +152 -0
- data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.h +60 -0
- data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.c +83 -0
- data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.c +82 -0
- data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.c +83 -0
- data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.c +86 -0
- data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.c +74 -0
- data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.c +64 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.c +54 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.c +53 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +73 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.c +72 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.c +81 -0
- data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.c +92 -0
- data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.h +65 -0
- data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.c +95 -0
- data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.h +55 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/http.upbdefs.c +34 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/http.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.c +59 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.c +54 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.c +47 -0
- data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.c +40 -0
- data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.c +61 -0
- data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.c +38 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.c +386 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.h +165 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.c +39 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.c +37 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.c +65 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.h +50 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.c +39 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.c +66 -0
- data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.h +75 -0
- data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +42 -0
- data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.c +70 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.h +45 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.c +56 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.c +33 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.h +30 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.c +49 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.c +43 -0
- data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.c +42 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.c +62 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.c +45 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.c +49 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.c +68 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.h +40 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.c +51 -0
- data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.h +35 -0
- data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +307 -0
- data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.h +145 -0
- data/src/core/ext/xds/certificate_provider_factory.h +7 -5
- data/src/core/ext/xds/certificate_provider_store.cc +84 -0
- data/src/core/ext/xds/certificate_provider_store.h +65 -8
- data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +119 -0
- data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +72 -0
- data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +28 -140
- data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +6 -4
- data/src/core/ext/xds/xds_api.cc +241 -718
- data/src/core/ext/xds/xds_api.h +50 -9
- data/src/core/ext/xds/xds_bootstrap.cc +172 -25
- data/src/core/ext/xds/xds_bootstrap.h +23 -7
- data/src/core/ext/xds/xds_certificate_provider.cc +240 -0
- data/src/core/ext/xds/xds_certificate_provider.h +74 -0
- data/src/core/ext/xds/xds_client.cc +161 -128
- data/src/core/ext/xds/xds_client.h +12 -11
- data/src/core/ext/xds/xds_client_stats.cc +41 -4
- data/src/core/ext/xds/xds_client_stats.h +2 -2
- data/src/core/lib/channel/channel_args.cc +2 -1
- data/src/core/lib/channel/channel_trace.cc +4 -2
- data/src/core/lib/channel/channelz.h +2 -2
- data/src/core/lib/channel/handshaker.h +2 -2
- data/src/core/lib/compression/compression.cc +8 -4
- data/src/core/lib/compression/compression_internal.cc +10 -5
- data/src/core/lib/compression/compression_internal.h +2 -1
- data/src/core/lib/compression/stream_compression_identity.cc +1 -3
- data/src/core/lib/debug/stats_data.cc +1 -0
- data/src/core/lib/gpr/cpu_iphone.cc +10 -2
- data/src/core/lib/gpr/log_linux.cc +17 -3
- data/src/core/lib/gpr/log_posix.cc +13 -1
- data/src/core/lib/gpr/log_windows.cc +16 -4
- data/src/core/lib/gpr/murmur_hash.cc +1 -1
- data/src/core/lib/gpr/string.cc +1 -1
- data/src/core/lib/gpr/time_precise.cc +3 -2
- data/src/core/lib/gpr/tls.h +4 -0
- data/src/core/lib/gpr/tls_msvc.h +2 -0
- data/src/core/lib/gpr/tls_stdcpp.h +48 -0
- data/src/core/lib/gpr/useful.h +5 -4
- data/src/core/lib/gprpp/dual_ref_counted.h +44 -49
- data/src/core/lib/gprpp/examine_stack.cc +43 -0
- data/src/core/lib/gprpp/examine_stack.h +46 -0
- data/src/core/lib/gprpp/fork.cc +2 -2
- data/src/core/lib/gprpp/manual_constructor.h +1 -1
- data/src/core/lib/gprpp/orphanable.h +4 -8
- data/src/core/lib/gprpp/ref_counted.h +40 -46
- data/src/core/lib/gprpp/ref_counted_ptr.h +9 -11
- data/src/core/lib/{security/authorization/mock_cel/statusor.h → gprpp/stat.h} +13 -25
- data/src/core/lib/gprpp/stat_posix.cc +49 -0
- data/src/core/lib/gprpp/stat_windows.cc +48 -0
- data/src/core/lib/gprpp/thd.h +2 -2
- data/src/core/lib/gprpp/thd_posix.cc +36 -36
- data/src/core/lib/http/parser.cc +46 -25
- data/src/core/lib/iomgr/error.cc +2 -1
- data/src/core/lib/iomgr/ev_epollex_linux.cc +8 -4
- data/src/core/lib/iomgr/exec_ctx.cc +1 -1
- data/src/core/lib/iomgr/executor/mpmcqueue.h +5 -5
- data/src/core/lib/iomgr/executor/threadpool.h +3 -3
- data/src/core/lib/iomgr/parse_address.cc +84 -6
- data/src/core/lib/iomgr/parse_address.h +20 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +2 -1
- data/src/core/lib/iomgr/python_util.h +3 -3
- data/src/core/lib/iomgr/resolve_address_posix.cc +1 -5
- data/src/core/lib/iomgr/tcp_posix.cc +3 -2
- data/src/core/lib/iomgr/timer_custom.cc +2 -2
- data/src/core/lib/iomgr/unix_sockets_posix.cc +27 -15
- data/src/core/lib/iomgr/unix_sockets_posix.h +5 -0
- data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +7 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.cc +2 -2
- data/src/core/lib/json/json.h +2 -2
- data/src/core/lib/json/json_reader.cc +8 -4
- data/src/core/lib/json/json_util.h +167 -0
- data/src/core/lib/json/json_writer.cc +2 -1
- data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +3 -1
- data/src/core/lib/security/authorization/mock_cel/cel_expression.h +5 -4
- data/src/core/lib/security/authorization/mock_cel/cel_value.h +4 -0
- data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +6 -6
- data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +10 -9
- data/src/core/lib/security/context/security_context.h +3 -1
- data/src/core/lib/security/credentials/credentials.cc +1 -1
- data/src/core/lib/security/credentials/credentials.h +3 -3
- data/src/core/lib/security/credentials/external/aws_request_signer.cc +208 -0
- data/src/core/lib/security/credentials/external/aws_request_signer.h +73 -0
- data/src/core/lib/security/credentials/external/external_account_credentials.cc +311 -0
- data/src/core/lib/security/credentials/external/external_account_credentials.h +118 -0
- data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +136 -0
- data/src/core/lib/security/credentials/external/file_external_account_credentials.h +49 -0
- data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +211 -0
- data/src/core/lib/security/credentials/external/url_external_account_credentials.h +59 -0
- data/src/core/lib/security/credentials/insecure/insecure_credentials.cc +51 -0
- data/src/core/lib/security/credentials/jwt/json_token.cc +5 -2
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +4 -3
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +5 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -2
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +35 -5
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +12 -8
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +78 -0
- data/src/core/lib/security/{certificate_provider.h → credentials/tls/grpc_tls_certificate_provider.h} +32 -18
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +77 -149
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +58 -187
- data/src/core/lib/security/credentials/tls/tls_credentials.cc +16 -12
- data/src/core/lib/security/credentials/tls/tls_credentials.h +2 -2
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +2 -2
- data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +88 -0
- data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +70 -0
- data/src/core/lib/security/security_connector/load_system_roots.h +4 -0
- data/src/core/lib/security/security_connector/load_system_roots_linux.h +2 -0
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +2 -2
- data/src/core/lib/security/security_connector/security_connector.cc +1 -1
- data/src/core/lib/security/security_connector/security_connector.h +4 -2
- data/src/core/lib/security/security_connector/ssl_utils.h +4 -2
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +293 -275
- data/src/core/lib/security/security_connector/tls/tls_security_connector.h +106 -61
- data/src/core/lib/security/transport/security_handshaker.cc +1 -1
- data/src/core/lib/security/transport/server_auth_filter.cc +2 -1
- data/src/core/lib/security/util/json_util.h +1 -0
- data/src/core/lib/slice/slice.cc +7 -4
- data/src/core/lib/slice/slice_buffer.cc +2 -1
- data/src/core/lib/slice/slice_intern.cc +2 -2
- data/src/core/lib/surface/call.cc +9 -8
- data/src/core/lib/surface/completion_queue.cc +7 -6
- data/src/core/lib/surface/server.cc +4 -2
- data/src/core/lib/surface/server.h +2 -2
- data/src/core/lib/surface/validate_metadata.h +3 -0
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/authority_override.h +2 -0
- data/src/core/lib/transport/bdp_estimator.cc +1 -1
- data/src/core/lib/transport/byte_stream.h +3 -3
- data/src/core/lib/transport/connectivity_state.h +3 -3
- data/src/core/lib/transport/metadata.h +2 -2
- data/src/core/lib/transport/timeout_encoding.cc +4 -4
- data/src/core/lib/transport/transport.cc +5 -3
- data/src/core/lib/transport/transport.h +1 -1
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -4
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +4 -3
- data/src/core/tsi/fake_transport_security.cc +1 -0
- data/src/core/tsi/local_transport_security.cc +5 -1
- data/src/core/tsi/local_transport_security.h +6 -7
- data/src/core/tsi/ssl/session_cache/ssl_session.h +3 -0
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +4 -1
- data/src/core/tsi/ssl_transport_security.cc +14 -7
- data/src/core/tsi/ssl_transport_security.h +3 -0
- data/src/core/tsi/transport_security.cc +4 -2
- data/src/ruby/ext/grpc/extconf.rb +1 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +22 -14
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +36 -24
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/abseil-cpp/absl/algorithm/container.h +59 -22
- data/third_party/abseil-cpp/absl/base/attributes.h +99 -38
- data/third_party/abseil-cpp/absl/base/call_once.h +1 -1
- data/third_party/abseil-cpp/absl/base/casts.h +9 -6
- data/third_party/abseil-cpp/absl/base/config.h +60 -17
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +428 -335
- data/third_party/abseil-cpp/absl/base/internal/bits.h +17 -16
- data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +5 -0
- data/third_party/abseil-cpp/absl/base/internal/dynamic_annotations.h +398 -0
- data/third_party/abseil-cpp/absl/base/internal/invoke.h +4 -4
- data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +1 -1
- data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +29 -1
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +2 -2
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +7 -5
- data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +25 -38
- data/third_party/abseil-cpp/absl/base/internal/spinlock.h +19 -25
- data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +8 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +28 -5
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +8 -0
- data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +3 -1
- data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +2 -2
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +3 -3
- data/third_party/abseil-cpp/absl/base/macros.h +36 -109
- data/third_party/abseil-cpp/absl/base/optimization.h +61 -1
- data/third_party/abseil-cpp/absl/base/options.h +31 -4
- data/third_party/abseil-cpp/absl/base/policy_checks.h +1 -1
- data/third_party/abseil-cpp/absl/base/thread_annotations.h +94 -39
- data/third_party/abseil-cpp/absl/container/fixed_array.h +42 -25
- data/third_party/abseil-cpp/absl/container/flat_hash_set.h +2 -1
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +33 -36
- data/third_party/abseil-cpp/absl/container/internal/common.h +6 -2
- data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +33 -8
- data/third_party/abseil-cpp/absl/container/internal/container_memory.h +49 -29
- data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +15 -0
- data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +24 -7
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +2 -1
- data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +35 -11
- data/third_party/abseil-cpp/absl/container/internal/have_sse.h +10 -9
- data/third_party/abseil-cpp/absl/container/internal/layout.h +7 -5
- data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +55 -34
- data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +5 -4
- data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +66 -16
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +4 -0
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +13 -4
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +43 -24
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +12 -3
- data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +10 -2
- data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +22 -1
- data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +0 -21
- data/third_party/abseil-cpp/absl/debugging/symbolize.cc +12 -1
- data/third_party/abseil-cpp/absl/debugging/symbolize_darwin.inc +101 -0
- data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +100 -20
- data/third_party/abseil-cpp/absl/functional/bind_front.h +184 -0
- data/third_party/abseil-cpp/absl/functional/function_ref.h +1 -1
- data/third_party/abseil-cpp/absl/functional/internal/front_binder.h +95 -0
- data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +2 -2
- data/third_party/abseil-cpp/absl/hash/hash.h +6 -5
- data/third_party/abseil-cpp/absl/hash/internal/hash.h +73 -65
- data/third_party/abseil-cpp/absl/memory/memory.h +4 -0
- data/third_party/abseil-cpp/absl/meta/type_traits.h +2 -8
- data/third_party/abseil-cpp/absl/numeric/int128.cc +13 -27
- data/third_party/abseil-cpp/absl/numeric/int128.h +16 -15
- data/third_party/abseil-cpp/absl/status/internal/status_internal.h +51 -0
- data/third_party/abseil-cpp/absl/status/status.cc +4 -6
- data/third_party/abseil-cpp/absl/status/status.h +502 -113
- data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +5 -10
- data/third_party/abseil-cpp/absl/strings/charconv.cc +2 -2
- data/third_party/abseil-cpp/absl/strings/cord.cc +91 -112
- data/third_party/abseil-cpp/absl/strings/cord.h +360 -205
- data/third_party/abseil-cpp/absl/strings/escaping.cc +9 -9
- data/third_party/abseil-cpp/absl/strings/internal/char_map.h +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +2 -2
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +2 -2
- data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +45 -23
- data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +222 -136
- data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +136 -64
- data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.cc +1 -1
- data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +14 -21
- data/third_party/abseil-cpp/absl/strings/internal/str_format/checker.h +7 -14
- data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.cc +31 -7
- data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h +147 -135
- data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +999 -87
- data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.h +3 -3
- data/third_party/abseil-cpp/absl/strings/internal/str_format/output.h +4 -12
- data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.cc +8 -6
- data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +13 -11
- data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +2 -2
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +4 -4
- data/third_party/abseil-cpp/absl/strings/str_cat.h +1 -1
- data/third_party/abseil-cpp/absl/strings/str_format.h +289 -13
- data/third_party/abseil-cpp/absl/strings/str_split.cc +2 -2
- data/third_party/abseil-cpp/absl/strings/str_split.h +1 -0
- data/third_party/abseil-cpp/absl/strings/string_view.h +26 -19
- data/third_party/abseil-cpp/absl/strings/substitute.cc +5 -5
- data/third_party/abseil-cpp/absl/strings/substitute.h +32 -29
- data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +3 -3
- data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +3 -3
- data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +28 -28
- data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +4 -16
- data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +1 -1
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +8 -0
- data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +2 -2
- data/third_party/abseil-cpp/absl/synchronization/mutex.cc +75 -64
- data/third_party/abseil-cpp/absl/synchronization/mutex.h +15 -6
- data/third_party/abseil-cpp/absl/time/civil_time.cc +9 -9
- data/third_party/abseil-cpp/absl/time/clock.cc +3 -3
- data/third_party/abseil-cpp/absl/time/duration.cc +90 -59
- data/third_party/abseil-cpp/absl/time/format.cc +43 -36
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +26 -16
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +4 -2
- data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/zone_info_source.h +1 -1
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +136 -29
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +13 -21
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +1 -1
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +136 -129
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +4 -5
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +8 -7
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +6 -6
- data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +2 -1
- data/third_party/abseil-cpp/absl/time/time.h +15 -16
- data/third_party/abseil-cpp/absl/types/internal/variant.h +4 -4
- data/third_party/abseil-cpp/absl/types/optional.h +9 -9
- data/third_party/abseil-cpp/absl/types/span.h +49 -36
- data/third_party/abseil-cpp/absl/utility/utility.h +2 -2
- data/third_party/address_sorting/include/address_sorting/address_sorting.h +2 -0
- data/third_party/boringssl-with-bazel/err_data.c +340 -336
- data/third_party/boringssl-with-bazel/src/crypto/bio/bio.c +2 -0
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +173 -35
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +46 -7
- data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +8 -2
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +90 -63
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +60 -60
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +179 -47
- data/third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c +766 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +10 -0
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_data.c +5 -3
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +14 -14
- data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +1 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +24 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +7 -5
- data/third_party/boringssl-with-bazel/src/include/openssl/base.h +5 -2
- data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +4 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/des.h +6 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/opensslconf.h +3 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/pem.h +202 -134
- data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +55 -1
- data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +4 -0
- data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +31 -23
- data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +435 -394
- data/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc +18 -5
- data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +35 -0
- data/third_party/boringssl-with-bazel/src/ssl/internal.h +36 -1
- data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +42 -1
- data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +67 -0
- data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +11 -14
- data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +216 -11
- data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +53 -11
- data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +133 -39
- data/third_party/upb/upb/def.c +2169 -0
- data/third_party/upb/upb/def.h +330 -0
- data/third_party/upb/upb/def.hpp +525 -0
- data/third_party/upb/upb/reflection.c +391 -0
- data/third_party/upb/upb/reflection.h +168 -0
- data/third_party/upb/upb/text_encode.c +398 -0
- data/third_party/upb/upb/text_encode.h +35 -0
- metadata +227 -37
- data/src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc +0 -571
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +0 -129
@@ -16,26 +16,21 @@
|
|
16
16
|
#include <atomic>
|
17
17
|
|
18
18
|
#include "absl/base/attributes.h"
|
19
|
+
#include "absl/base/internal/atomic_hook.h"
|
19
20
|
|
20
21
|
namespace absl {
|
21
22
|
ABSL_NAMESPACE_BEGIN
|
22
23
|
namespace status_internal {
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
// (MSVC's `std::atomic` has trouble constant initializing).
|
27
|
-
std::atomic<StatusPayloadPrinter>& GetStatusPayloadPrinterStorage() {
|
28
|
-
ABSL_CONST_INIT static std::atomic<StatusPayloadPrinter> instance{nullptr};
|
29
|
-
return instance;
|
30
|
-
}
|
31
|
-
} // namespace
|
25
|
+
ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES
|
26
|
+
static absl::base_internal::AtomicHook<StatusPayloadPrinter> storage;
|
32
27
|
|
33
28
|
void SetStatusPayloadPrinter(StatusPayloadPrinter printer) {
|
34
|
-
|
29
|
+
storage.Store(printer);
|
35
30
|
}
|
36
31
|
|
37
32
|
StatusPayloadPrinter GetStatusPayloadPrinter() {
|
38
|
-
return
|
33
|
+
return storage.Load();
|
39
34
|
}
|
40
35
|
|
41
36
|
} // namespace status_internal
|
@@ -619,10 +619,10 @@ from_chars_result FromCharsImpl(const char* first, const char* last,
|
|
619
619
|
// Either we failed to parse a hex float after the "0x", or we read
|
620
620
|
// "0xinf" or "0xnan" which we don't want to match.
|
621
621
|
//
|
622
|
-
// However, a
|
622
|
+
// However, a string that begins with "0x" also begins with "0", which
|
623
623
|
// is normally a valid match for the number zero. So we want these
|
624
624
|
// strings to match zero unless fmt_flags is `scientific`. (This flag
|
625
|
-
// means an exponent is required, which the
|
625
|
+
// means an exponent is required, which the string "0" does not have.)
|
626
626
|
if (fmt_flags == chars_format::scientific) {
|
627
627
|
result.ec = std::errc::invalid_argument;
|
628
628
|
} else {
|
@@ -15,10 +15,12 @@
|
|
15
15
|
#include "absl/strings/cord.h"
|
16
16
|
|
17
17
|
#include <algorithm>
|
18
|
+
#include <atomic>
|
18
19
|
#include <cstddef>
|
19
20
|
#include <cstdio>
|
20
21
|
#include <cstdlib>
|
21
22
|
#include <iomanip>
|
23
|
+
#include <iostream>
|
22
24
|
#include <limits>
|
23
25
|
#include <ostream>
|
24
26
|
#include <sstream>
|
@@ -28,6 +30,7 @@
|
|
28
30
|
|
29
31
|
#include "absl/base/casts.h"
|
30
32
|
#include "absl/base/internal/raw_logging.h"
|
33
|
+
#include "absl/base/macros.h"
|
31
34
|
#include "absl/base/port.h"
|
32
35
|
#include "absl/container/fixed_array.h"
|
33
36
|
#include "absl/container/inlined_vector.h"
|
@@ -58,48 +61,6 @@ enum CordRepKind {
|
|
58
61
|
FLAT = 3,
|
59
62
|
};
|
60
63
|
|
61
|
-
namespace {
|
62
|
-
|
63
|
-
// Type used with std::allocator for allocating and deallocating
|
64
|
-
// `CordRepExternal`. std::allocator is used because it opaquely handles the
|
65
|
-
// different new / delete overloads available on a given platform.
|
66
|
-
struct alignas(absl::cord_internal::ExternalRepAlignment()) ExternalAllocType {
|
67
|
-
unsigned char value[absl::cord_internal::ExternalRepAlignment()];
|
68
|
-
};
|
69
|
-
|
70
|
-
// Returns the number of objects to pass in to std::allocator<ExternalAllocType>
|
71
|
-
// allocate() and deallocate() to create enough room for `CordRepExternal` with
|
72
|
-
// `releaser_size` bytes on the end.
|
73
|
-
constexpr size_t GetExternalAllocNumObjects(size_t releaser_size) {
|
74
|
-
// Be sure to round up since `releaser_size` could be smaller than
|
75
|
-
// `sizeof(ExternalAllocType)`.
|
76
|
-
return (sizeof(CordRepExternal) + releaser_size + sizeof(ExternalAllocType) -
|
77
|
-
1) /
|
78
|
-
sizeof(ExternalAllocType);
|
79
|
-
}
|
80
|
-
|
81
|
-
// Allocates enough memory for `CordRepExternal` and a releaser with size
|
82
|
-
// `releaser_size` bytes.
|
83
|
-
void* AllocateExternal(size_t releaser_size) {
|
84
|
-
return std::allocator<ExternalAllocType>().allocate(
|
85
|
-
GetExternalAllocNumObjects(releaser_size));
|
86
|
-
}
|
87
|
-
|
88
|
-
// Deallocates the memory for a `CordRepExternal` assuming it was allocated with
|
89
|
-
// a releaser of given size and alignment.
|
90
|
-
void DeallocateExternal(CordRepExternal* p, size_t releaser_size) {
|
91
|
-
std::allocator<ExternalAllocType>().deallocate(
|
92
|
-
reinterpret_cast<ExternalAllocType*>(p),
|
93
|
-
GetExternalAllocNumObjects(releaser_size));
|
94
|
-
}
|
95
|
-
|
96
|
-
// Returns a pointer to the type erased releaser for the given CordRepExternal.
|
97
|
-
void* GetExternalReleaser(CordRepExternal* rep) {
|
98
|
-
return rep + 1;
|
99
|
-
}
|
100
|
-
|
101
|
-
} // namespace
|
102
|
-
|
103
64
|
namespace cord_internal {
|
104
65
|
|
105
66
|
inline CordRepConcat* CordRep::concat() {
|
@@ -136,8 +97,6 @@ inline const CordRepExternal* CordRep::external() const {
|
|
136
97
|
|
137
98
|
static const size_t kFlatOverhead = offsetof(CordRep, data);
|
138
99
|
|
139
|
-
static_assert(kFlatOverhead == 13, "Unittests assume kFlatOverhead == 13");
|
140
|
-
|
141
100
|
// Largest and smallest flat node lengths we are willing to allocate
|
142
101
|
// Flat allocation size is stored in tag, which currently can encode sizes up
|
143
102
|
// to 4K, encoded as multiple of either 8 or 32 bytes.
|
@@ -195,52 +154,18 @@ static_assert(Fibonacci(63) == 6557470319842,
|
|
195
154
|
// The root node depth is allowed to become twice as large to reduce rebalancing
|
196
155
|
// for larger strings (see IsRootBalanced).
|
197
156
|
static constexpr uint64_t min_length[] = {
|
198
|
-
Fibonacci(2),
|
199
|
-
Fibonacci(
|
200
|
-
Fibonacci(
|
201
|
-
Fibonacci(
|
202
|
-
Fibonacci(
|
203
|
-
Fibonacci(
|
204
|
-
Fibonacci(
|
205
|
-
Fibonacci(
|
206
|
-
Fibonacci(
|
207
|
-
Fibonacci(
|
208
|
-
Fibonacci(
|
209
|
-
Fibonacci(
|
210
|
-
Fibonacci(14),
|
211
|
-
Fibonacci(15),
|
212
|
-
Fibonacci(16),
|
213
|
-
Fibonacci(17),
|
214
|
-
Fibonacci(18),
|
215
|
-
Fibonacci(19),
|
216
|
-
Fibonacci(20),
|
217
|
-
Fibonacci(21),
|
218
|
-
Fibonacci(22),
|
219
|
-
Fibonacci(23),
|
220
|
-
Fibonacci(24),
|
221
|
-
Fibonacci(25),
|
222
|
-
Fibonacci(26),
|
223
|
-
Fibonacci(27),
|
224
|
-
Fibonacci(28),
|
225
|
-
Fibonacci(29),
|
226
|
-
Fibonacci(30),
|
227
|
-
Fibonacci(31),
|
228
|
-
Fibonacci(32),
|
229
|
-
Fibonacci(33),
|
230
|
-
Fibonacci(34),
|
231
|
-
Fibonacci(35),
|
232
|
-
Fibonacci(36),
|
233
|
-
Fibonacci(37),
|
234
|
-
Fibonacci(38),
|
235
|
-
Fibonacci(39),
|
236
|
-
Fibonacci(40),
|
237
|
-
Fibonacci(41),
|
238
|
-
Fibonacci(42),
|
239
|
-
Fibonacci(43),
|
240
|
-
Fibonacci(44),
|
241
|
-
Fibonacci(45),
|
242
|
-
Fibonacci(46),
|
243
|
-
Fibonacci(47),
|
157
|
+
Fibonacci(2), Fibonacci(3), Fibonacci(4), Fibonacci(5),
|
158
|
+
Fibonacci(6), Fibonacci(7), Fibonacci(8), Fibonacci(9),
|
159
|
+
Fibonacci(10), Fibonacci(11), Fibonacci(12), Fibonacci(13),
|
160
|
+
Fibonacci(14), Fibonacci(15), Fibonacci(16), Fibonacci(17),
|
161
|
+
Fibonacci(18), Fibonacci(19), Fibonacci(20), Fibonacci(21),
|
162
|
+
Fibonacci(22), Fibonacci(23), Fibonacci(24), Fibonacci(25),
|
163
|
+
Fibonacci(26), Fibonacci(27), Fibonacci(28), Fibonacci(29),
|
164
|
+
Fibonacci(30), Fibonacci(31), Fibonacci(32), Fibonacci(33),
|
165
|
+
Fibonacci(34), Fibonacci(35), Fibonacci(36), Fibonacci(37),
|
166
|
+
Fibonacci(38), Fibonacci(39), Fibonacci(40), Fibonacci(41),
|
167
|
+
Fibonacci(42), Fibonacci(43), Fibonacci(44), Fibonacci(45),
|
168
|
+
Fibonacci(46), Fibonacci(47),
|
244
169
|
0xffffffffffffffffull, // Avoid overflow
|
245
170
|
};
|
246
171
|
|
@@ -337,11 +262,7 @@ static void UnrefInternal(CordRep* rep) {
|
|
337
262
|
}
|
338
263
|
} else if (rep->tag == EXTERNAL) {
|
339
264
|
CordRepExternal* rep_external = rep->external();
|
340
|
-
|
341
|
-
void* releaser = GetExternalReleaser(rep_external);
|
342
|
-
size_t releaser_size = rep_external->releaser_invoker(releaser, data);
|
343
|
-
rep_external->~CordRepExternal();
|
344
|
-
DeallocateExternal(rep_external, releaser_size);
|
265
|
+
rep_external->releaser_invoker(rep_external);
|
345
266
|
rep = nullptr;
|
346
267
|
} else if (rep->tag == SUBSTRING) {
|
347
268
|
CordRepSubstring* rep_substring = rep->substring();
|
@@ -491,18 +412,12 @@ static CordRep* NewTree(const char* data,
|
|
491
412
|
|
492
413
|
namespace cord_internal {
|
493
414
|
|
494
|
-
|
495
|
-
absl::string_view data, ExternalReleaserInvoker invoker,
|
496
|
-
size_t releaser_size) {
|
415
|
+
void InitializeCordRepExternal(absl::string_view data, CordRepExternal* rep) {
|
497
416
|
assert(!data.empty());
|
498
|
-
|
499
|
-
void* raw_rep = AllocateExternal(releaser_size);
|
500
|
-
auto* rep = new (raw_rep) CordRepExternal();
|
501
417
|
rep->length = data.size();
|
502
418
|
rep->tag = EXTERNAL;
|
503
419
|
rep->base = data.data();
|
504
|
-
rep
|
505
|
-
return {VerifyTree(rep), GetExternalReleaser(rep)};
|
420
|
+
VerifyTree(rep);
|
506
421
|
}
|
507
422
|
|
508
423
|
} // namespace cord_internal
|
@@ -526,10 +441,7 @@ static CordRep* NewSubstring(CordRep* child, size_t offset, size_t length) {
|
|
526
441
|
// --------------------------------------------------------------------
|
527
442
|
// Cord::InlineRep functions
|
528
443
|
|
529
|
-
|
530
|
-
#ifndef COMPILER_MSVC
|
531
|
-
const unsigned char Cord::InlineRep::kMaxInline;
|
532
|
-
#endif // COMPILER_MSVC
|
444
|
+
constexpr unsigned char Cord::InlineRep::kMaxInline;
|
533
445
|
|
534
446
|
inline void Cord::InlineRep::set_data(const char* data, size_t n,
|
535
447
|
bool nullify_tail) {
|
@@ -585,7 +497,7 @@ void Cord::InlineRep::AppendTree(CordRep* tree) {
|
|
585
497
|
}
|
586
498
|
|
587
499
|
void Cord::InlineRep::PrependTree(CordRep* tree) {
|
588
|
-
|
500
|
+
assert(tree != nullptr);
|
589
501
|
size_t len = data_[kMaxInline];
|
590
502
|
if (len == 0) {
|
591
503
|
set_tree(tree);
|
@@ -738,6 +650,37 @@ Cord::Cord(absl::string_view src) {
|
|
738
650
|
}
|
739
651
|
}
|
740
652
|
|
653
|
+
template <typename T, Cord::EnableIfString<T>>
|
654
|
+
Cord::Cord(T&& src) {
|
655
|
+
if (
|
656
|
+
// String is short: copy data to avoid external block overhead.
|
657
|
+
src.size() <= kMaxBytesToCopy ||
|
658
|
+
// String is wasteful: copy data to avoid pinning too much unused memory.
|
659
|
+
src.size() < src.capacity() / 2
|
660
|
+
) {
|
661
|
+
if (src.size() <= InlineRep::kMaxInline) {
|
662
|
+
contents_.set_data(src.data(), src.size(), false);
|
663
|
+
} else {
|
664
|
+
contents_.set_tree(NewTree(src.data(), src.size(), 0));
|
665
|
+
}
|
666
|
+
} else {
|
667
|
+
struct StringReleaser {
|
668
|
+
void operator()(absl::string_view /* data */) {}
|
669
|
+
std::string data;
|
670
|
+
};
|
671
|
+
const absl::string_view original_data = src;
|
672
|
+
auto* rep = static_cast<
|
673
|
+
::absl::cord_internal::CordRepExternalImpl<StringReleaser>*>(
|
674
|
+
absl::cord_internal::NewExternalRep(
|
675
|
+
original_data, StringReleaser{std::forward<T>(src)}));
|
676
|
+
// Moving src may have invalidated its data pointer, so adjust it.
|
677
|
+
rep->base = rep->template get<0>().data.data();
|
678
|
+
contents_.set_tree(rep);
|
679
|
+
}
|
680
|
+
}
|
681
|
+
|
682
|
+
template Cord::Cord(std::string&& src);
|
683
|
+
|
741
684
|
// The destruction code is separate so that the compiler can determine
|
742
685
|
// that it does not need to call the destructor on a moved-from Cord.
|
743
686
|
void Cord::DestroyCordSlow() {
|
@@ -775,6 +718,18 @@ Cord& Cord::operator=(absl::string_view src) {
|
|
775
718
|
return *this;
|
776
719
|
}
|
777
720
|
|
721
|
+
template <typename T, Cord::EnableIfString<T>>
|
722
|
+
Cord& Cord::operator=(T&& src) {
|
723
|
+
if (src.size() <= kMaxBytesToCopy) {
|
724
|
+
*this = absl::string_view(src);
|
725
|
+
} else {
|
726
|
+
*this = Cord(std::forward<T>(src));
|
727
|
+
}
|
728
|
+
return *this;
|
729
|
+
}
|
730
|
+
|
731
|
+
template Cord& Cord::operator=(std::string&& src);
|
732
|
+
|
778
733
|
// TODO(sanjay): Move to Cord::InlineRep section of file. For now,
|
779
734
|
// we keep it here to make diffs easier.
|
780
735
|
void Cord::InlineRep::AppendArray(const char* src_data, size_t src_size) {
|
@@ -886,6 +841,17 @@ void Cord::Append(const Cord& src) { AppendImpl(src); }
|
|
886
841
|
|
887
842
|
void Cord::Append(Cord&& src) { AppendImpl(std::move(src)); }
|
888
843
|
|
844
|
+
template <typename T, Cord::EnableIfString<T>>
|
845
|
+
void Cord::Append(T&& src) {
|
846
|
+
if (src.size() <= kMaxBytesToCopy) {
|
847
|
+
Append(absl::string_view(src));
|
848
|
+
} else {
|
849
|
+
Append(Cord(std::forward<T>(src)));
|
850
|
+
}
|
851
|
+
}
|
852
|
+
|
853
|
+
template void Cord::Append(std::string&& src);
|
854
|
+
|
889
855
|
void Cord::Prepend(const Cord& src) {
|
890
856
|
CordRep* src_tree = src.contents_.tree();
|
891
857
|
if (src_tree != nullptr) {
|
@@ -915,6 +881,17 @@ void Cord::Prepend(absl::string_view src) {
|
|
915
881
|
}
|
916
882
|
}
|
917
883
|
|
884
|
+
template <typename T, Cord::EnableIfString<T>>
|
885
|
+
inline void Cord::Prepend(T&& src) {
|
886
|
+
if (src.size() <= kMaxBytesToCopy) {
|
887
|
+
Prepend(absl::string_view(src));
|
888
|
+
} else {
|
889
|
+
Prepend(Cord(std::forward<T>(src)));
|
890
|
+
}
|
891
|
+
}
|
892
|
+
|
893
|
+
template void Cord::Prepend(std::string&& src);
|
894
|
+
|
918
895
|
static CordRep* RemovePrefixFrom(CordRep* node, size_t n) {
|
919
896
|
if (n >= node->length) return nullptr;
|
920
897
|
if (n == 0) return Ref(node);
|
@@ -1175,7 +1152,7 @@ class CordForest {
|
|
1175
1152
|
void AddNode(CordRep* node) {
|
1176
1153
|
CordRep* sum = nullptr;
|
1177
1154
|
|
1178
|
-
// Collect together everything with which we will merge node
|
1155
|
+
// Collect together everything with which we will merge with node
|
1179
1156
|
int i = 0;
|
1180
1157
|
for (; node->length > min_length[i + 1]; ++i) {
|
1181
1158
|
auto& tree_at_i = trees_[i];
|
@@ -1506,7 +1483,8 @@ void Cord::CopyToArraySlowPath(char* dst) const {
|
|
1506
1483
|
}
|
1507
1484
|
|
1508
1485
|
Cord::ChunkIterator& Cord::ChunkIterator::operator++() {
|
1509
|
-
|
1486
|
+
ABSL_HARDENING_ASSERT(bytes_remaining_ > 0 &&
|
1487
|
+
"Attempted to iterate past `end()`");
|
1510
1488
|
assert(bytes_remaining_ >= current_chunk_.size());
|
1511
1489
|
bytes_remaining_ -= current_chunk_.size();
|
1512
1490
|
|
@@ -1545,7 +1523,8 @@ Cord::ChunkIterator& Cord::ChunkIterator::operator++() {
|
|
1545
1523
|
}
|
1546
1524
|
|
1547
1525
|
Cord Cord::ChunkIterator::AdvanceAndReadBytes(size_t n) {
|
1548
|
-
|
1526
|
+
ABSL_HARDENING_ASSERT(bytes_remaining_ >= n &&
|
1527
|
+
"Attempted to iterate past `end()`");
|
1549
1528
|
Cord subcord;
|
1550
1529
|
|
1551
1530
|
if (n <= InlineRep::kMaxInline) {
|
@@ -1716,7 +1695,7 @@ void Cord::ChunkIterator::AdvanceBytesSlowPath(size_t n) {
|
|
1716
1695
|
}
|
1717
1696
|
|
1718
1697
|
char Cord::operator[](size_t i) const {
|
1719
|
-
|
1698
|
+
ABSL_HARDENING_ASSERT(i < size());
|
1720
1699
|
size_t offset = i;
|
1721
1700
|
const CordRep* rep = contents_.tree();
|
1722
1701
|
if (rep == nullptr) {
|
@@ -11,25 +11,52 @@
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
// See the License for the specific language governing permissions and
|
13
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
14
|
//
|
21
|
-
//
|
22
|
-
//
|
15
|
+
// -----------------------------------------------------------------------------
|
16
|
+
// File: cord.h
|
17
|
+
// -----------------------------------------------------------------------------
|
18
|
+
//
|
19
|
+
// This file defines the `absl::Cord` data structure and operations on that data
|
20
|
+
// structure. A Cord is a string-like sequence of characters optimized for
|
21
|
+
// specific use cases. Unlike a `std::string`, which stores an array of
|
22
|
+
// contiguous characters, Cord data is stored in a structure consisting of
|
23
|
+
// separate, reference-counted "chunks." (Currently, this implementation is a
|
24
|
+
// tree structure, though that implementation may change.)
|
25
|
+
//
|
26
|
+
// Because a Cord consists of these chunks, data can be added to or removed from
|
27
|
+
// a Cord during its lifetime. Chunks may also be shared between Cords. Unlike a
|
28
|
+
// `std::string`, a Cord can therefore accomodate data that changes over its
|
29
|
+
// lifetime, though it's not quite "mutable"; it can change only in the
|
30
|
+
// attachment, detachment, or rearrangement of chunks of its constituent data.
|
31
|
+
//
|
32
|
+
// A Cord provides some benefit over `std::string` under the following (albeit
|
33
|
+
// narrow) circumstances:
|
34
|
+
//
|
35
|
+
// * Cord data is designed to grow and shrink over a Cord's lifetime. Cord
|
36
|
+
// provides efficient insertions and deletions at the start and end of the
|
37
|
+
// character sequences, avoiding copies in those cases. Static data should
|
38
|
+
// generally be stored as strings.
|
39
|
+
// * External memory consisting of string-like data can be directly added to
|
40
|
+
// a Cord without requiring copies or allocations.
|
41
|
+
// * Cord data may be shared and copied cheaply. Cord provides a copy-on-write
|
42
|
+
// implementation and cheap sub-Cord operations. Copying a Cord is an O(1)
|
43
|
+
// operation.
|
44
|
+
//
|
45
|
+
// As a consequence to the above, Cord data is generally large. Small data
|
46
|
+
// should generally use strings, as construction of a Cord requires some
|
47
|
+
// overhead. Small Cords (<= 15 bytes) are represented inline, but most small
|
48
|
+
// Cords are expected to grow over their lifetimes.
|
49
|
+
//
|
50
|
+
// Note that because a Cord is made up of separate chunked data, random access
|
51
|
+
// to character data within a Cord is slower than within a `std::string`.
|
52
|
+
//
|
53
|
+
// Thread Safety
|
54
|
+
//
|
23
55
|
// Cord has the same thread-safety properties as many other types like
|
24
56
|
// std::string, std::vector<>, int, etc -- it is thread-compatible. In
|
25
|
-
// particular, if
|
26
|
-
//
|
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
|
57
|
+
// particular, if threads do not call non-const methods, then it is safe to call
|
58
|
+
// const methods without synchronization. Copying a Cord produces a new instance
|
59
|
+
// that can be used concurrently with the original in arbitrary ways.
|
33
60
|
|
34
61
|
#ifndef ABSL_STRINGS_CORD_H_
|
35
62
|
#define ABSL_STRINGS_CORD_H_
|
@@ -38,12 +65,12 @@
|
|
38
65
|
#include <cstddef>
|
39
66
|
#include <cstdint>
|
40
67
|
#include <cstring>
|
41
|
-
#include <
|
68
|
+
#include <iosfwd>
|
42
69
|
#include <iterator>
|
43
70
|
#include <string>
|
71
|
+
#include <type_traits>
|
44
72
|
|
45
73
|
#include "absl/base/internal/endian.h"
|
46
|
-
#include "absl/base/internal/invoke.h"
|
47
74
|
#include "absl/base/internal/per_thread_tls.h"
|
48
75
|
#include "absl/base/macros.h"
|
49
76
|
#include "absl/base/port.h"
|
@@ -53,6 +80,7 @@
|
|
53
80
|
#include "absl/strings/internal/cord_internal.h"
|
54
81
|
#include "absl/strings/internal/resize_uninitialized.h"
|
55
82
|
#include "absl/strings/string_view.h"
|
83
|
+
#include "absl/types/optional.h"
|
56
84
|
|
57
85
|
namespace absl {
|
58
86
|
ABSL_NAMESPACE_BEGIN
|
@@ -61,12 +89,35 @@ class CordTestPeer;
|
|
61
89
|
template <typename Releaser>
|
62
90
|
Cord MakeCordFromExternal(absl::string_view, Releaser&&);
|
63
91
|
void CopyCordToString(const Cord& src, std::string* dst);
|
64
|
-
namespace hash_internal {
|
65
|
-
template <typename H>
|
66
|
-
H HashFragmentedCord(H, const Cord&);
|
67
|
-
}
|
68
92
|
|
69
|
-
//
|
93
|
+
// Cord
|
94
|
+
//
|
95
|
+
// A Cord is a sequence of characters, designed to be more efficient than a
|
96
|
+
// `std::string` in certain circumstances: namely, large string data that needs
|
97
|
+
// to change over its lifetime or shared, especially when such data is shared
|
98
|
+
// across API boundaries.
|
99
|
+
//
|
100
|
+
// A Cord stores its character data in a structure that allows efficient prepend
|
101
|
+
// and append operations. This makes a Cord useful for large string data sent
|
102
|
+
// over in a wire format that may need to be prepended or appended at some point
|
103
|
+
// during the data exchange (e.g. HTTP, protocol buffers). For example, a
|
104
|
+
// Cord is useful for storing an HTTP request, and prepending an HTTP header to
|
105
|
+
// such a request.
|
106
|
+
//
|
107
|
+
// Cords should not be used for storing general string data, however. They
|
108
|
+
// require overhead to construct and are slower than strings for random access.
|
109
|
+
//
|
110
|
+
// The Cord API provides the following common API operations:
|
111
|
+
//
|
112
|
+
// * Create or assign Cords out of existing string data, memory, or other Cords
|
113
|
+
// * Append and prepend data to an existing Cord
|
114
|
+
// * Create new Sub-Cords from existing Cord data
|
115
|
+
// * Swap Cord data and compare Cord equality
|
116
|
+
// * Write out Cord data by constructing a `std::string`
|
117
|
+
//
|
118
|
+
// Additionally, the API provides iterator utilities to iterate through Cord
|
119
|
+
// data via chunks or character bytes.
|
120
|
+
//
|
70
121
|
class Cord {
|
71
122
|
private:
|
72
123
|
template <typename T>
|
@@ -74,51 +125,53 @@ class Cord {
|
|
74
125
|
absl::enable_if_t<std::is_same<T, std::string>::value, int>;
|
75
126
|
|
76
127
|
public:
|
77
|
-
//
|
78
|
-
// Constructors, destructors and helper factories
|
128
|
+
// Cord::Cord() Constructors.
|
79
129
|
|
80
|
-
//
|
130
|
+
// Creates an empty Cord.
|
81
131
|
constexpr Cord() noexcept;
|
82
132
|
|
83
|
-
// Cord is copyable and efficiently
|
84
|
-
// The moved-from state is valid but unspecified.
|
133
|
+
// Creates a Cord from an existing Cord. Cord is copyable and efficiently
|
134
|
+
// movable. The moved-from state is valid but unspecified.
|
85
135
|
Cord(const Cord& src);
|
86
136
|
Cord(Cord&& src) noexcept;
|
87
137
|
Cord& operator=(const Cord& x);
|
88
138
|
Cord& operator=(Cord&& x) noexcept;
|
89
139
|
|
90
|
-
//
|
91
|
-
//
|
140
|
+
// Creates a Cord from a `src` string. This constructor is marked explicit to
|
141
|
+
// prevent implicit Cord constructions from arguments convertible to an
|
142
|
+
// `absl::string_view`.
|
92
143
|
explicit Cord(absl::string_view src);
|
93
144
|
Cord& operator=(absl::string_view src);
|
94
145
|
|
95
|
-
//
|
96
|
-
//
|
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.
|
146
|
+
// Creates a Cord from a `std::string&&` rvalue. These constructors are
|
147
|
+
// templated to avoid ambiguities for types that are convertible to both
|
148
|
+
// `absl::string_view` and `std::string`, such as `const char*`.
|
100
149
|
template <typename T, EnableIfString<T> = 0>
|
101
|
-
explicit Cord(T&& src)
|
150
|
+
explicit Cord(T&& src);
|
102
151
|
template <typename T, EnableIfString<T> = 0>
|
103
152
|
Cord& operator=(T&& src);
|
104
153
|
|
105
|
-
//
|
154
|
+
// Cord::~Cord()
|
155
|
+
//
|
156
|
+
// Destructs the Cord.
|
106
157
|
~Cord() {
|
107
158
|
if (contents_.is_tree()) DestroyCordSlow();
|
108
159
|
}
|
109
160
|
|
110
|
-
//
|
111
|
-
// `data` are not copied.
|
161
|
+
// MakeCordFromExternal()
|
112
162
|
//
|
113
|
-
//
|
114
|
-
//
|
115
|
-
//
|
116
|
-
//
|
117
|
-
//
|
118
|
-
//
|
119
|
-
//
|
120
|
-
//
|
121
|
-
//
|
163
|
+
// Creates a Cord that takes ownership of external string memory. The
|
164
|
+
// contents of `data` are not copied to the Cord; instead, the external
|
165
|
+
// memory is added to the Cord and reference-counted. This data may not be
|
166
|
+
// changed for the life of the Cord, though it may be prepended or appended
|
167
|
+
// to.
|
168
|
+
//
|
169
|
+
// `MakeCordFromExternal()` takes a callable "releaser" that is invoked when
|
170
|
+
// the reference count for `data` reaches zero. As noted above, this data must
|
171
|
+
// remain live until the releaser is invoked. The callable releaser also must:
|
172
|
+
//
|
173
|
+
// * be move constructible
|
174
|
+
// * support `void operator()(absl::string_view) const` or `void operator()`
|
122
175
|
//
|
123
176
|
// Example:
|
124
177
|
//
|
@@ -127,13 +180,13 @@ class Cord {
|
|
127
180
|
// FillBlock(block);
|
128
181
|
// return absl::MakeCordFromExternal(
|
129
182
|
// block->ToStringView(),
|
130
|
-
// [pool, block](absl::string_view
|
131
|
-
// pool->FreeBlock(block);
|
183
|
+
// [pool, block](absl::string_view v) {
|
184
|
+
// pool->FreeBlock(block, v);
|
132
185
|
// });
|
133
186
|
// }
|
134
187
|
//
|
135
|
-
// WARNING:
|
136
|
-
// For example, consider the following:
|
188
|
+
// WARNING: Because a Cord can be reference-counted, it's likely a bug if your
|
189
|
+
// releaser doesn't do anything. For example, consider the following:
|
137
190
|
//
|
138
191
|
// void Foo(const char* buffer, int len) {
|
139
192
|
// auto c = absl::MakeCordFromExternal(absl::string_view(buffer, len),
|
@@ -147,97 +200,143 @@ class Cord {
|
|
147
200
|
template <typename Releaser>
|
148
201
|
friend Cord MakeCordFromExternal(absl::string_view data, Releaser&& releaser);
|
149
202
|
|
150
|
-
//
|
151
|
-
//
|
152
|
-
|
203
|
+
// Cord::Clear()
|
204
|
+
//
|
205
|
+
// Releases the Cord data. Any nodes that share data with other Cords, if
|
206
|
+
// applicable, will have their reference counts reduced by 1.
|
153
207
|
void Clear();
|
154
208
|
|
209
|
+
// Cord::Append()
|
210
|
+
//
|
211
|
+
// Appends data to the Cord, which may come from another Cord or other string
|
212
|
+
// data.
|
155
213
|
void Append(const Cord& src);
|
156
214
|
void Append(Cord&& src);
|
157
215
|
void Append(absl::string_view src);
|
158
216
|
template <typename T, EnableIfString<T> = 0>
|
159
217
|
void Append(T&& src);
|
160
218
|
|
219
|
+
// Cord::Prepend()
|
220
|
+
//
|
221
|
+
// Prepends data to the Cord, which may come from another Cord or other string
|
222
|
+
// data.
|
161
223
|
void Prepend(const Cord& src);
|
162
224
|
void Prepend(absl::string_view src);
|
163
225
|
template <typename T, EnableIfString<T> = 0>
|
164
226
|
void Prepend(T&& src);
|
165
227
|
|
228
|
+
// Cord::RemovePrefix()
|
229
|
+
//
|
230
|
+
// Removes the first `n` bytes of a Cord.
|
166
231
|
void RemovePrefix(size_t n);
|
167
232
|
void RemoveSuffix(size_t n);
|
168
233
|
|
169
|
-
//
|
234
|
+
// Cord::Subcord()
|
235
|
+
//
|
236
|
+
// Returns a new Cord representing the subrange [pos, pos + new_size) of
|
170
237
|
// *this. If pos >= size(), the result is empty(). If
|
171
238
|
// (pos + new_size) >= size(), the result is the subrange [pos, size()).
|
172
239
|
Cord Subcord(size_t pos, size_t new_size) const;
|
173
240
|
|
174
|
-
|
241
|
+
// Cord::swap()
|
242
|
+
//
|
243
|
+
// Swaps the contents of the Cord with `other`.
|
244
|
+
void swap(Cord& other) noexcept;
|
175
245
|
|
176
|
-
//
|
177
|
-
//
|
246
|
+
// swap()
|
247
|
+
//
|
248
|
+
// Swaps the contents of two Cords.
|
249
|
+
friend void swap(Cord& x, Cord& y) noexcept {
|
250
|
+
x.swap(y);
|
251
|
+
}
|
178
252
|
|
253
|
+
// Cord::size()
|
254
|
+
//
|
255
|
+
// Returns the size of the Cord.
|
179
256
|
size_t size() const;
|
257
|
+
|
258
|
+
// Cord::empty()
|
259
|
+
//
|
260
|
+
// Determines whether the given Cord is empty, returning `true` is so.
|
180
261
|
bool empty() const;
|
181
262
|
|
182
|
-
//
|
183
|
-
//
|
184
|
-
//
|
263
|
+
// Cord::EstimatedMemoryUsage()
|
264
|
+
//
|
265
|
+
// Returns the *approximate* number of bytes held in full or in part by this
|
266
|
+
// Cord (which may not remain the same between invocations). Note that Cords
|
267
|
+
// that share memory could each be "charged" independently for the same shared
|
268
|
+
// memory.
|
185
269
|
size_t EstimatedMemoryUsage() const;
|
186
270
|
|
187
|
-
//
|
188
|
-
//
|
189
|
-
|
190
|
-
//
|
191
|
-
//
|
192
|
-
//
|
271
|
+
// Cord::Compare()
|
272
|
+
//
|
273
|
+
// Compares 'this' Cord with rhs. This function and its relatives treat Cords
|
274
|
+
// as sequences of unsigned bytes. The comparison is a straightforward
|
275
|
+
// lexicographic comparison. `Cord::Compare()` returns values as follows:
|
276
|
+
//
|
193
277
|
// -1 'this' Cord is smaller
|
194
278
|
// 0 two Cords are equal
|
195
279
|
// 1 'this' Cord is larger
|
196
280
|
int Compare(absl::string_view rhs) const;
|
197
281
|
int Compare(const Cord& rhs) const;
|
198
282
|
|
199
|
-
//
|
283
|
+
// Cord::StartsWith()
|
284
|
+
//
|
285
|
+
// Determines whether the Cord starts with the passed string data `rhs`.
|
200
286
|
bool StartsWith(const Cord& rhs) const;
|
201
287
|
bool StartsWith(absl::string_view rhs) const;
|
288
|
+
|
289
|
+
// Cord::EndsWidth()
|
290
|
+
//
|
291
|
+
// Determines whether the Cord ends with the passed string data `rhs`.
|
202
292
|
bool EndsWith(absl::string_view rhs) const;
|
203
293
|
bool EndsWith(const Cord& rhs) const;
|
204
294
|
|
205
|
-
//
|
206
|
-
//
|
207
|
-
|
295
|
+
// Cord::operator std::string()
|
296
|
+
//
|
297
|
+
// Converts a Cord into a `std::string()`. This operator is marked explicit to
|
298
|
+
// prevent unintended Cord usage in functions that take a string.
|
208
299
|
explicit operator std::string() const;
|
209
300
|
|
210
|
-
//
|
301
|
+
// CopyCordToString()
|
302
|
+
//
|
303
|
+
// Copies the contents of a `src` Cord into a `*dst` string.
|
211
304
|
//
|
212
|
-
// This function optimizes the case of reusing the destination
|
305
|
+
// This function optimizes the case of reusing the destination string since it
|
213
306
|
// can reuse previously allocated capacity. However, this function does not
|
214
307
|
// guarantee that pointers previously returned by `dst->data()` remain valid
|
215
308
|
// even if `*dst` had enough capacity to hold `src`. If `*dst` is a new
|
216
309
|
// object, prefer to simply use the conversion operator to `std::string`.
|
217
310
|
friend void CopyCordToString(const Cord& src, std::string* dst);
|
218
311
|
|
219
|
-
// --------------------------------------------------------------------
|
220
|
-
// Iteration
|
221
|
-
|
222
312
|
class CharIterator;
|
223
313
|
|
224
|
-
|
225
|
-
//
|
226
|
-
|
314
|
+
//----------------------------------------------------------------------------
|
315
|
+
// Cord::ChunkIterator
|
316
|
+
//----------------------------------------------------------------------------
|
227
317
|
//
|
228
|
-
//
|
318
|
+
// A `Cord::ChunkIterator` allows iteration over the constituent chunks of its
|
319
|
+
// Cord. Such iteration allows you to perform non-const operatons on the data
|
320
|
+
// of a Cord without modifying it.
|
321
|
+
//
|
322
|
+
// Generally, you do not instantiate a `Cord::ChunkIterator` directly;
|
323
|
+
// instead, you create one implicitly through use of the `Cord::Chunks()`
|
324
|
+
// member function.
|
325
|
+
//
|
326
|
+
// The `Cord::ChunkIterator` has the following properties:
|
327
|
+
//
|
328
|
+
// * The iterator is invalidated after any non-const operation on the
|
329
|
+
// Cord object over which it iterates.
|
229
330
|
// * The `string_view` returned by dereferencing a valid, non-`end()`
|
230
331
|
// iterator is guaranteed to be non-empty.
|
231
|
-
// *
|
232
|
-
//
|
233
|
-
// *
|
234
|
-
//
|
235
|
-
//
|
236
|
-
//
|
237
|
-
//
|
238
|
-
//
|
239
|
-
// equivalent to `value_type`.
|
240
|
-
// * The iterator keeps state that can grow for `Cord`s that contain many
|
332
|
+
// * Two `ChunkIterator` objects can be compared equal if and only if they
|
333
|
+
// remain valid and iterate over the same Cord.
|
334
|
+
// * The iterator in this case is a proxy iterator; the `string_view`
|
335
|
+
// returned by the iterator does not live inside the Cord, and its
|
336
|
+
// lifetime is limited to the lifetime of the iterator itself. To help
|
337
|
+
// prevent lifetime issues, `ChunkIterator::reference` is not a true
|
338
|
+
// reference type and is equivalent to `value_type`.
|
339
|
+
// * The iterator keeps state that can grow for Cords that contain many
|
241
340
|
// nodes and are imbalanced due to sharing. Prefer to pass this type by
|
242
341
|
// const reference instead of by value.
|
243
342
|
class ChunkIterator {
|
@@ -286,10 +385,13 @@ class Cord {
|
|
286
385
|
stack_of_right_children_;
|
287
386
|
};
|
288
387
|
|
388
|
+
// Cord::ChunkIterator::chunk_begin()
|
389
|
+
//
|
289
390
|
// Returns an iterator to the first chunk of the `Cord`.
|
290
391
|
//
|
291
|
-
//
|
292
|
-
//
|
392
|
+
// Generally, prefer using `Cord::Chunks()` within a range-based for loop for
|
393
|
+
// iterating over the chunks of a Cord. This method may be useful for getting
|
394
|
+
// a `ChunkIterator` where range-based for-loops are not useful.
|
293
395
|
//
|
294
396
|
// Example:
|
295
397
|
//
|
@@ -298,13 +400,28 @@ class Cord {
|
|
298
400
|
// return std::find(c.chunk_begin(), c.chunk_end(), s);
|
299
401
|
// }
|
300
402
|
ChunkIterator chunk_begin() const;
|
403
|
+
|
404
|
+
// Cord::ChunkItertator::chunk_end()
|
405
|
+
//
|
301
406
|
// Returns an iterator one increment past the last chunk of the `Cord`.
|
407
|
+
//
|
408
|
+
// Generally, prefer using `Cord::Chunks()` within a range-based for loop for
|
409
|
+
// iterating over the chunks of a Cord. This method may be useful for getting
|
410
|
+
// a `ChunkIterator` where range-based for-loops may not be available.
|
302
411
|
ChunkIterator chunk_end() const;
|
303
412
|
|
304
|
-
|
305
|
-
//
|
413
|
+
//----------------------------------------------------------------------------
|
414
|
+
// Cord::ChunkIterator::ChunkRange
|
415
|
+
//----------------------------------------------------------------------------
|
416
|
+
//
|
417
|
+
// `ChunkRange` is a helper class for iterating over the chunks of the `Cord`,
|
418
|
+
// producing an iterator which can be used within a range-based for loop.
|
419
|
+
// Construction of a `ChunkRange` will return an iterator pointing to the
|
420
|
+
// first chunk of the Cord. Generally, do not construct a `ChunkRange`
|
421
|
+
// directly; instead, prefer to use the `Cord::Chunks()` method.
|
306
422
|
//
|
307
|
-
//
|
423
|
+
// Implementation note: `ChunkRange` is simply a convenience wrapper over
|
424
|
+
// `Cord::chunk_begin()` and `Cord::chunk_end()`.
|
308
425
|
class ChunkRange {
|
309
426
|
public:
|
310
427
|
explicit ChunkRange(const Cord* cord) : cord_(cord) {}
|
@@ -316,8 +433,11 @@ class Cord {
|
|
316
433
|
const Cord* cord_;
|
317
434
|
};
|
318
435
|
|
319
|
-
//
|
320
|
-
//
|
436
|
+
// Cord::Chunks()
|
437
|
+
//
|
438
|
+
// Returns a `Cord::ChunkIterator::ChunkRange` for iterating over the chunks
|
439
|
+
// of a `Cord` with a range-based for-loop. For most iteration tasks on a
|
440
|
+
// Cord, use `Cord::Chunks()` to retrieve this iterator.
|
321
441
|
//
|
322
442
|
// Example:
|
323
443
|
//
|
@@ -334,22 +454,30 @@ class Cord {
|
|
334
454
|
// }
|
335
455
|
ChunkRange Chunks() const;
|
336
456
|
|
337
|
-
|
338
|
-
//
|
339
|
-
|
457
|
+
//----------------------------------------------------------------------------
|
458
|
+
// Cord::CharIterator
|
459
|
+
//----------------------------------------------------------------------------
|
460
|
+
//
|
461
|
+
// A `Cord::CharIterator` allows iteration over the constituent characters of
|
462
|
+
// a `Cord`.
|
340
463
|
//
|
341
|
-
//
|
342
|
-
//
|
343
|
-
//
|
344
|
-
//
|
345
|
-
//
|
346
|
-
//
|
464
|
+
// Generally, you do not instantiate a `Cord::CharIterator` directly; instead,
|
465
|
+
// you create one implicitly through use of the `Cord::Chars()` member
|
466
|
+
// function.
|
467
|
+
//
|
468
|
+
// A `Cord::CharIterator` has the following properties:
|
469
|
+
//
|
470
|
+
// * The iterator is invalidated after any non-const operation on the
|
471
|
+
// Cord object over which it iterates.
|
472
|
+
// * Two `CharIterator` objects can be compared equal if and only if they
|
473
|
+
// remain valid and iterate over the same Cord.
|
474
|
+
// * The iterator keeps state that can grow for Cords that contain many
|
347
475
|
// nodes and are imbalanced due to sharing. Prefer to pass this type by
|
348
476
|
// const reference instead of by value.
|
349
|
-
// * This type cannot
|
350
|
-
// sections of memory. This violates the requirement
|
351
|
-
//
|
352
|
-
//
|
477
|
+
// * This type cannot act as a forward iterator because a `Cord` can reuse
|
478
|
+
// sections of memory. This fact violates the requirement for forward
|
479
|
+
// iterators to compare equal if dereferencing them returns the same
|
480
|
+
// object.
|
353
481
|
class CharIterator {
|
354
482
|
public:
|
355
483
|
using iterator_category = std::input_iterator_tag;
|
@@ -375,34 +503,56 @@ class Cord {
|
|
375
503
|
ChunkIterator chunk_iterator_;
|
376
504
|
};
|
377
505
|
|
378
|
-
//
|
506
|
+
// Cord::CharIterator::AdvanceAndRead()
|
379
507
|
//
|
380
|
-
// `
|
381
|
-
//
|
382
|
-
//
|
508
|
+
// Advances the `Cord::CharIterator` by `n_bytes` and returns the bytes
|
509
|
+
// advanced as a separate `Cord`. `n_bytes` must be less than or equal to the
|
510
|
+
// number of bytes within the Cord; otherwise, behavior is undefined. It is
|
511
|
+
// valid to pass `char_end()` and `0`.
|
383
512
|
static Cord AdvanceAndRead(CharIterator* it, size_t n_bytes);
|
384
513
|
|
385
|
-
//
|
514
|
+
// Cord::CharIterator::Advance()
|
386
515
|
//
|
387
|
-
// `n_bytes` must be less than
|
388
|
-
//
|
389
|
-
// `char_end()` and 0
|
516
|
+
// Advances the `Cord::CharIterator` by `n_bytes`. `n_bytes` must be less than
|
517
|
+
// or equal to the number of bytes remaining within the Cord; otherwise,
|
518
|
+
// behavior is undefined. It is valid to pass `char_end()` and `0`.
|
390
519
|
static void Advance(CharIterator* it, size_t n_bytes);
|
391
520
|
|
521
|
+
// Cord::CharIterator::ChunkRemaining()
|
522
|
+
//
|
392
523
|
// Returns the longest contiguous view starting at the iterator's position.
|
393
524
|
//
|
394
525
|
// `it` must be dereferenceable.
|
395
526
|
static absl::string_view ChunkRemaining(const CharIterator& it);
|
396
527
|
|
528
|
+
// Cord::CharIterator::char_begin()
|
529
|
+
//
|
397
530
|
// Returns an iterator to the first character of the `Cord`.
|
531
|
+
//
|
532
|
+
// Generally, prefer using `Cord::Chars()` within a range-based for loop for
|
533
|
+
// iterating over the chunks of a Cord. This method may be useful for getting
|
534
|
+
// a `CharIterator` where range-based for-loops may not be available.
|
398
535
|
CharIterator char_begin() const;
|
536
|
+
|
537
|
+
// Cord::CharIterator::char_end()
|
538
|
+
//
|
399
539
|
// Returns an iterator to one past the last character of the `Cord`.
|
540
|
+
//
|
541
|
+
// Generally, prefer using `Cord::Chars()` within a range-based for loop for
|
542
|
+
// iterating over the chunks of a Cord. This method may be useful for getting
|
543
|
+
// a `CharIterator` where range-based for-loops are not useful.
|
400
544
|
CharIterator char_end() const;
|
401
545
|
|
402
|
-
//
|
403
|
-
//
|
546
|
+
// Cord::CharIterator::CharRange
|
547
|
+
//
|
548
|
+
// `CharRange` is a helper class for iterating over the characters of a
|
549
|
+
// producing an iterator which can be used within a range-based for loop.
|
550
|
+
// Construction of a `CharRange` will return an iterator pointing to the first
|
551
|
+
// character of the Cord. Generally, do not construct a `CharRange` directly;
|
552
|
+
// instead, prefer to use the `Cord::Chars()` method show below.
|
404
553
|
//
|
405
|
-
//
|
554
|
+
// Implementation note: `CharRange` is simply a convenience wrapper over
|
555
|
+
// `Cord::char_begin()` and `Cord::char_end()`.
|
406
556
|
class CharRange {
|
407
557
|
public:
|
408
558
|
explicit CharRange(const Cord* cord) : cord_(cord) {}
|
@@ -414,8 +564,11 @@ class Cord {
|
|
414
564
|
const Cord* cord_;
|
415
565
|
};
|
416
566
|
|
417
|
-
//
|
418
|
-
//
|
567
|
+
// Cord::CharIterator::Chars()
|
568
|
+
//
|
569
|
+
// Returns a `Cord::CharIterator` for iterating over the characters of a
|
570
|
+
// `Cord` with a range-based for-loop. For most character-based iteration
|
571
|
+
// tasks on a Cord, use `Cord::Chars()` to retrieve this iterator.
|
419
572
|
//
|
420
573
|
// Example:
|
421
574
|
//
|
@@ -432,32 +585,51 @@ class Cord {
|
|
432
585
|
// }
|
433
586
|
CharRange Chars() const;
|
434
587
|
|
435
|
-
//
|
436
|
-
//
|
437
|
-
|
438
|
-
//
|
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.
|
588
|
+
// Cord::operator[]
|
589
|
+
//
|
590
|
+
// Gets the "i"th character of the Cord and returns it, provided that
|
591
|
+
// 0 <= i < Cord.size().
|
444
592
|
//
|
445
|
-
//
|
593
|
+
// NOTE: This routine is reasonably efficient. It is roughly
|
594
|
+
// logarithmic based on the number of chunks that make up the cord. Still,
|
595
|
+
// if you need to iterate over the contents of a cord, you should
|
596
|
+
// use a CharIterator/ChunkIterator rather than call operator[] or Get()
|
597
|
+
// repeatedly in a loop.
|
446
598
|
char operator[](size_t i) const;
|
447
599
|
|
600
|
+
// Cord::TryFlat()
|
601
|
+
//
|
602
|
+
// If this cord's representation is a single flat array, returns a
|
603
|
+
// string_view referencing that array. Otherwise returns nullopt.
|
604
|
+
absl::optional<absl::string_view> TryFlat() const;
|
605
|
+
|
606
|
+
// Cord::Flatten()
|
607
|
+
//
|
448
608
|
// Flattens the cord into a single array and returns a view of the data.
|
449
609
|
//
|
450
610
|
// If the cord was already flat, the contents are not modified.
|
451
611
|
absl::string_view Flatten();
|
452
612
|
|
613
|
+
// Supports absl::Cord as a sink object for absl::Format().
|
614
|
+
friend void AbslFormatFlush(absl::Cord* cord, absl::string_view part) {
|
615
|
+
cord->Append(part);
|
616
|
+
}
|
617
|
+
|
618
|
+
template <typename H>
|
619
|
+
friend H AbslHashValue(H hash_state, const absl::Cord& c) {
|
620
|
+
absl::optional<absl::string_view> maybe_flat = c.TryFlat();
|
621
|
+
if (maybe_flat.has_value()) {
|
622
|
+
return H::combine(std::move(hash_state), *maybe_flat);
|
623
|
+
}
|
624
|
+
return c.HashFragmented(std::move(hash_state));
|
625
|
+
}
|
626
|
+
|
453
627
|
private:
|
454
628
|
friend class CordTestPeer;
|
455
|
-
template <typename H>
|
456
|
-
friend H absl::hash_internal::HashFragmentedCord(H, const Cord&);
|
457
629
|
friend bool operator==(const Cord& lhs, const Cord& rhs);
|
458
630
|
friend bool operator==(const Cord& lhs, absl::string_view rhs);
|
459
631
|
|
460
|
-
//
|
632
|
+
// Calls the provided function once for each cord chunk, in order. Unlike
|
461
633
|
// Chunks(), this API will not allocate memory.
|
462
634
|
void ForEachChunk(absl::FunctionRef<void(absl::string_view)>) const;
|
463
635
|
|
@@ -469,16 +641,15 @@ class Cord {
|
|
469
641
|
// class so that we can isolate the bulk of cord.cc from changes
|
470
642
|
// to the representation.
|
471
643
|
//
|
472
|
-
// InlineRep holds either
|
473
|
-
// bytes.
|
644
|
+
// InlineRep holds either a tree pointer, or an array of kMaxInline bytes.
|
474
645
|
class InlineRep {
|
475
646
|
public:
|
476
|
-
static
|
647
|
+
static constexpr unsigned char kMaxInline = 15;
|
477
648
|
static_assert(kMaxInline >= sizeof(absl::cord_internal::CordRep*), "");
|
478
649
|
// Tag byte & kMaxInline means we are storing a pointer.
|
479
|
-
static
|
650
|
+
static constexpr unsigned char kTreeFlag = 1 << 4;
|
480
651
|
// Tag byte & kProfiledFlag means we are profiling the Cord.
|
481
|
-
static
|
652
|
+
static constexpr unsigned char kProfiledFlag = 1 << 5;
|
482
653
|
|
483
654
|
constexpr InlineRep() : data_{} {}
|
484
655
|
InlineRep(const InlineRep& src);
|
@@ -502,7 +673,7 @@ class Cord {
|
|
502
673
|
void replace_tree(absl::cord_internal::CordRep* rep);
|
503
674
|
// Returns non-null iff was holding a pointer
|
504
675
|
absl::cord_internal::CordRep* clear();
|
505
|
-
//
|
676
|
+
// Converts to pointer if necessary.
|
506
677
|
absl::cord_internal::CordRep* force_tree(size_t extra_hint);
|
507
678
|
void reduce_size(size_t n); // REQUIRES: holding data
|
508
679
|
void remove_prefix(size_t n); // REQUIRES: holding data
|
@@ -531,7 +702,7 @@ class Cord {
|
|
531
702
|
}
|
532
703
|
void CopyTo(std::string* dst) const {
|
533
704
|
// memcpy is much faster when operating on a known size. On most supported
|
534
|
-
// platforms, the small
|
705
|
+
// platforms, the small string optimization is large enough that resizing
|
535
706
|
// to 15 bytes does not cause a memory allocation.
|
536
707
|
absl::strings_internal::STLStringResizeUninitialized(dst,
|
537
708
|
sizeof(data_) - 1);
|
@@ -560,14 +731,14 @@ class Cord {
|
|
560
731
|
};
|
561
732
|
InlineRep contents_;
|
562
733
|
|
563
|
-
// Helper for MemoryUsage()
|
734
|
+
// Helper for MemoryUsage().
|
564
735
|
static size_t MemoryUsageAux(const absl::cord_internal::CordRep* rep);
|
565
736
|
|
566
|
-
// Helper for GetFlat()
|
737
|
+
// Helper for GetFlat() and TryFlat().
|
567
738
|
static bool GetFlatAux(absl::cord_internal::CordRep* rep,
|
568
739
|
absl::string_view* fragment);
|
569
740
|
|
570
|
-
// Helper for ForEachChunk()
|
741
|
+
// Helper for ForEachChunk().
|
571
742
|
static void ForEachChunkAux(
|
572
743
|
absl::cord_internal::CordRep* rep,
|
573
744
|
absl::FunctionRef<void(absl::string_view)> callback);
|
@@ -596,9 +767,20 @@ class Cord {
|
|
596
767
|
absl::cord_internal::CordRep* TakeRep() const&;
|
597
768
|
absl::cord_internal::CordRep* TakeRep() &&;
|
598
769
|
|
599
|
-
// Helper for Append()
|
770
|
+
// Helper for Append().
|
600
771
|
template <typename C>
|
601
772
|
void AppendImpl(C&& src);
|
773
|
+
|
774
|
+
// Helper for AbslHashValue().
|
775
|
+
template <typename H>
|
776
|
+
H HashFragmented(H hash_state) const {
|
777
|
+
typename H::AbslInternalPiecewiseCombiner combiner;
|
778
|
+
ForEachChunk([&combiner, &hash_state](absl::string_view chunk) {
|
779
|
+
hash_state = combiner.add_buffer(std::move(hash_state), chunk.data(),
|
780
|
+
chunk.size());
|
781
|
+
});
|
782
|
+
return H::combine(combiner.finalize(std::move(hash_state)), size());
|
783
|
+
}
|
602
784
|
};
|
603
785
|
|
604
786
|
ABSL_NAMESPACE_END
|
@@ -655,52 +837,27 @@ inline void SmallMemmove(char* dst, const char* src, size_t n,
|
|
655
837
|
}
|
656
838
|
}
|
657
839
|
|
658
|
-
|
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.
|
840
|
+
// Does non-template-specific `CordRepExternal` initialization.
|
665
841
|
// Expects `data` to be non-empty.
|
666
|
-
|
667
|
-
absl::string_view data, ExternalReleaserInvoker invoker,
|
668
|
-
size_t releaser_size);
|
842
|
+
void InitializeCordRepExternal(absl::string_view data, CordRepExternal* rep);
|
669
843
|
|
670
844
|
// Creates a new `CordRep` that owns `data` and `releaser` and returns a pointer
|
671
845
|
// to it, or `nullptr` if `data` was empty.
|
672
846
|
template <typename Releaser>
|
673
847
|
// NOLINTNEXTLINE - suppress clang-tidy raw pointer return.
|
674
848
|
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
849
|
using ReleaserType = absl::decay_t<Releaser>;
|
685
850
|
if (data.empty()) {
|
686
851
|
// Never create empty external nodes.
|
687
|
-
::
|
688
|
-
|
852
|
+
InvokeReleaser(Rank0{}, ReleaserType(std::forward<Releaser>(releaser)),
|
853
|
+
data);
|
689
854
|
return nullptr;
|
690
855
|
}
|
691
856
|
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
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;
|
857
|
+
CordRepExternal* rep = new CordRepExternalImpl<ReleaserType>(
|
858
|
+
std::forward<Releaser>(releaser), 0);
|
859
|
+
InitializeCordRepExternal(data, rep);
|
860
|
+
return rep;
|
704
861
|
}
|
705
862
|
|
706
863
|
// Overload for function reference types that dispatches using a function
|
@@ -834,16 +991,17 @@ inline Cord& Cord::operator=(const Cord& x) {
|
|
834
991
|
|
835
992
|
inline Cord::Cord(Cord&& src) noexcept : contents_(std::move(src.contents_)) {}
|
836
993
|
|
994
|
+
inline void Cord::swap(Cord& other) noexcept {
|
995
|
+
contents_.Swap(&other.contents_);
|
996
|
+
}
|
997
|
+
|
837
998
|
inline Cord& Cord::operator=(Cord&& x) noexcept {
|
838
999
|
contents_ = std::move(x.contents_);
|
839
1000
|
return *this;
|
840
1001
|
}
|
841
1002
|
|
842
|
-
template
|
843
|
-
|
844
|
-
*this = absl::string_view(src);
|
845
|
-
return *this;
|
846
|
-
}
|
1003
|
+
extern template Cord::Cord(std::string&& src);
|
1004
|
+
extern template Cord& Cord::operator=(std::string&& src);
|
847
1005
|
|
848
1006
|
inline size_t Cord::size() const {
|
849
1007
|
// Length is 1st field in str.rep_
|
@@ -860,6 +1018,18 @@ inline size_t Cord::EstimatedMemoryUsage() const {
|
|
860
1018
|
return result;
|
861
1019
|
}
|
862
1020
|
|
1021
|
+
inline absl::optional<absl::string_view> Cord::TryFlat() const {
|
1022
|
+
absl::cord_internal::CordRep* rep = contents_.tree();
|
1023
|
+
if (rep == nullptr) {
|
1024
|
+
return absl::string_view(contents_.data(), contents_.size());
|
1025
|
+
}
|
1026
|
+
absl::string_view fragment;
|
1027
|
+
if (GetFlatAux(rep, &fragment)) {
|
1028
|
+
return fragment;
|
1029
|
+
}
|
1030
|
+
return absl::nullopt;
|
1031
|
+
}
|
1032
|
+
|
863
1033
|
inline absl::string_view Cord::Flatten() {
|
864
1034
|
absl::cord_internal::CordRep* rep = contents_.tree();
|
865
1035
|
if (rep == nullptr) {
|
@@ -877,19 +1047,8 @@ inline void Cord::Append(absl::string_view src) {
|
|
877
1047
|
contents_.AppendArray(src.data(), src.size());
|
878
1048
|
}
|
879
1049
|
|
880
|
-
template
|
881
|
-
|
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
|
-
}
|
1050
|
+
extern template void Cord::Append(std::string&& src);
|
1051
|
+
extern template void Cord::Prepend(std::string&& src);
|
893
1052
|
|
894
1053
|
inline int Cord::Compare(const Cord& rhs) const {
|
895
1054
|
if (!contents_.is_tree() && !rhs.contents_.is_tree()) {
|
@@ -939,12 +1098,12 @@ inline bool Cord::ChunkIterator::operator!=(const ChunkIterator& other) const {
|
|
939
1098
|
}
|
940
1099
|
|
941
1100
|
inline Cord::ChunkIterator::reference Cord::ChunkIterator::operator*() const {
|
942
|
-
|
1101
|
+
ABSL_HARDENING_ASSERT(bytes_remaining_ != 0);
|
943
1102
|
return current_chunk_;
|
944
1103
|
}
|
945
1104
|
|
946
1105
|
inline Cord::ChunkIterator::pointer Cord::ChunkIterator::operator->() const {
|
947
|
-
|
1106
|
+
ABSL_HARDENING_ASSERT(bytes_remaining_ != 0);
|
948
1107
|
return ¤t_chunk_;
|
949
1108
|
}
|
950
1109
|
|
@@ -1098,10 +1257,6 @@ inline bool operator<=(absl::string_view x, const Cord& y) { return !(y < x); }
|
|
1098
1257
|
inline bool operator>=(const Cord& x, absl::string_view y) { return !(x < y); }
|
1099
1258
|
inline bool operator>=(absl::string_view x, const Cord& y) { return !(x < y); }
|
1100
1259
|
|
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
1260
|
// Some internals exposed to test code.
|
1106
1261
|
namespace strings_internal {
|
1107
1262
|
class CordTestAccess {
|