Skip to content

Commit

Permalink
Using string_view for operation names (#1870)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Feb 28, 2024
1 parent 7fd6e98 commit 1762a96
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 121 deletions.
2 changes: 1 addition & 1 deletion cpp/include/Ice/BatchRequestInterceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BatchRequest
* Obtains the name of the operation.
* @return The operation name.
*/
virtual const std::string& getOperation() const = 0;
virtual std::string_view getOperation() const = 0;

/**
* Obtains the proxy on which the batch request was invoked.
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/Instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class ICE_CLASS(ICE_API) CommunicatorObserver
* @param ctx The context specified by the user.
* @return The invocation observer to instrument the invocation.
*/
virtual InvocationObserverPtr getInvocationObserver(const std::optional<Ice::ObjectPrx>& prx, const ::std::string& operation, const ::Ice::Context& ctx) = 0;
virtual InvocationObserverPtr getInvocationObserver(const std::optional<Ice::ObjectPrx>& prx, std::string_view operation, const ::Ice::Context& ctx) = 0;

/**
* This method should return a dispatch observer for the given dispatch. The Ice run-time calls this method each
Expand Down
8 changes: 4 additions & 4 deletions cpp/include/Ice/ObserverHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ class ICE_API InvocationObserver : public ObserverHelperT<Ice::Instrumentation::
{
public:

InvocationObserver(const Ice::ObjectPrx&, const std::string&, const Ice::Context&);
InvocationObserver(Instance*, const std::string&);
InvocationObserver(const Ice::ObjectPrx& proxy, std::string_view operation, const Ice::Context& context);
InvocationObserver(Instance* instance, std::string_view operation);
InvocationObserver() = default;

void attach(const Ice::ObjectPrx&, const std::string&, const Ice::Context&);
void attach(Instance*, const std::string&);
void attach(const Ice::ObjectPrx&, std::string_view operation, const Ice::Context&);
void attach(Instance*, std::string_view operation);

void retried()
{
Expand Down
14 changes: 7 additions & 7 deletions cpp/include/Ice/OutgoingAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class ICE_API OutgoingAsync : public ProxyOutgoingAsyncBase

OutgoingAsync(Ice::ObjectPrx, bool);

void prepare(const std::string&, Ice::OperationMode, const Ice::Context&);
void prepare(std::string_view operation, Ice::OperationMode mode, const Ice::Context& context);

virtual bool sent();
virtual bool response();
Expand All @@ -206,8 +206,8 @@ class ICE_API OutgoingAsync : public ProxyOutgoingAsyncBase
virtual AsyncStatus invokeCollocated(CollocatedRequestHandler*);

void abort(std::exception_ptr);
void invoke(const std::string&);
void invoke(const std::string&, Ice::OperationMode, Ice::FormatType, const Ice::Context&,
void invoke(std::string_view);
void invoke(std::string_view, Ice::OperationMode, Ice::FormatType, const Ice::Context&,
std::function<void(Ice::OutputStream*)>);
void throwUserException();

Expand Down Expand Up @@ -324,7 +324,7 @@ class OutgoingAsyncT : public OutgoingAsync
using OutgoingAsync::OutgoingAsync;

void
invoke(const std::string& operation,
invoke(std::string_view operation,
Ice::OperationMode mode,
Ice::FormatType format,
const Ice::Context& ctx,
Expand All @@ -342,7 +342,7 @@ class OutgoingAsyncT : public OutgoingAsync
}

void
invoke(const std::string& operation,
invoke(std::string_view operation,
Ice::OperationMode mode,
Ice::FormatType format,
const Ice::Context& ctx,
Expand All @@ -368,7 +368,7 @@ class OutgoingAsyncT<void> : public OutgoingAsync
using OutgoingAsync::OutgoingAsync;

void
invoke(const std::string& operation,
invoke(std::string_view operation,
Ice::OperationMode mode,
Ice::FormatType format,
const Ice::Context& ctx,
Expand Down Expand Up @@ -480,7 +480,7 @@ class CustomLambdaOutgoing : public OutgoingAsync, public LambdaInvoke
}

void
invoke(const std::string& operation,
invoke(std::string_view operation,
Ice::OperationMode mode,
Ice::FormatType format,
const Ice::Context& ctx,
Expand Down
12 changes: 6 additions & 6 deletions cpp/include/Ice/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>
* exception, it throws it directly.
*/
bool
ice_invoke(const std::string& operation,
ice_invoke(std::string_view operation,
Ice::OperationMode mode,
const std::vector<Byte>& inParams,
std::vector<Ice::Byte>& outParams,
Expand All @@ -496,7 +496,7 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>
* @return The future object for the invocation.
*/
std::future<std::tuple<bool, std::vector<Ice::Byte>>>
ice_invokeAsync(const std::string& operation,
ice_invokeAsync(std::string_view operation,
Ice::OperationMode mode,
const std::vector<Byte>& inParams,
const Ice::Context& context = Ice::noExplicitContext) const;
Expand All @@ -513,7 +513,7 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>
* @return A function that can be called to cancel the invocation locally.
*/
std::function<void()>
ice_invokeAsync(const std::string& operation,
ice_invokeAsync(std::string_view operation,
Ice::OperationMode mode,
const std::vector<Ice::Byte>& inParams,
std::function<void(bool, std::vector<Ice::Byte>)> response,
Expand All @@ -534,7 +534,7 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>
* exception, it throws it directly.
*/
bool
ice_invoke(const std::string& operation,
ice_invoke(std::string_view operation,
Ice::OperationMode mode,
const std::pair<const Ice::Byte*, const Ice::Byte*>& inParams,
std::vector<Ice::Byte>& outParams,
Expand All @@ -549,7 +549,7 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>
* @return The future object for the invocation.
*/
std::future<std::tuple<bool, std::vector<Ice::Byte>>>
ice_invokeAsync(const std::string& operation,
ice_invokeAsync(std::string_view operation,
Ice::OperationMode mode,
const std::pair<const Ice::Byte*, const Ice::Byte*>& inParams,
const Ice::Context& context = Ice::noExplicitContext) const;
Expand All @@ -566,7 +566,7 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>
* @return A function that can be called to cancel the invocation locally.
*/
std::function<void()>
ice_invokeAsync(const std::string& operation,
ice_invokeAsync(std::string_view operation,
Ice::OperationMode mode,
const std::pair<const Ice::Byte*, const Ice::Byte*>& inParams,
std::function<void(bool, std::pair<const Ice::Byte*, const Ice::Byte*>)> response,
Expand Down
40 changes: 12 additions & 28 deletions cpp/src/Ice/BatchRequestQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,31 @@ namespace

const int udpOverhead = 20 + 8;

class BatchRequestI : public Ice::BatchRequest
class BatchRequestI final : public Ice::BatchRequest
{
public:

BatchRequestI(BatchRequestQueue& queue, const Ice::ObjectPrx& proxy, const string& operation, int size) :
_queue(queue), _proxy(proxy), _operation(operation), _size(size)
BatchRequestI(BatchRequestQueue& queue, const Ice::ObjectPrx& proxy, string_view operation, int size)
: _queue(queue),
_proxy(proxy),
_operation(operation),
_size(size)
{
}

virtual void
enqueue() const
{
_queue.enqueueBatchRequest(_proxy);
}
void enqueue() const final { _queue.enqueueBatchRequest(_proxy); }

virtual int
getSize() const
{
return _size;
}
int getSize() const final { return _size; }

virtual const std::string&
getOperation() const
{
return _operation;
}
string_view getOperation() const { return _operation; }

virtual const Ice::ObjectPrx&
getProxy() const
{
return _proxy;
}
const Ice::ObjectPrx& getProxy() const final { return _proxy; }

private:

BatchRequestQueue& _queue;
const Ice::ObjectPrx& _proxy;
const std::string& _operation;
const string_view _operation;
const int _size;
};

}

BatchRequestQueue::BatchRequestQueue(const InstancePtr& instance, bool datagram) :
Expand Down Expand Up @@ -100,7 +84,7 @@ BatchRequestQueue::prepareBatchRequest(OutputStream* os)
void
BatchRequestQueue::finishBatchRequest(OutputStream* os,
const Ice::ObjectPrx& proxy,
const std::string& operation)
string_view operation)
{
//
// No need for synchronization, no other threads are supposed
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/BatchRequestQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BatchRequestQueue
BatchRequestQueue(const InstancePtr&, bool);

void prepareBatchRequest(Ice::OutputStream*);
void finishBatchRequest(Ice::OutputStream*, const Ice::ObjectPrx&, const std::string&);
void finishBatchRequest(Ice::OutputStream*, const Ice::ObjectPrx&, std::string_view);
void abortBatchRequest(Ice::OutputStream*);

int swap(Ice::OutputStream*, bool&);
Expand Down
12 changes: 3 additions & 9 deletions cpp/src/Ice/CommunicatorI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ CommunicatorFlushBatchAsync::flushConnection(const ConnectionIPtr& con, Ice::Com
}

void
CommunicatorFlushBatchAsync::invoke(const string& operation, CompressBatch compressBatch)
CommunicatorFlushBatchAsync::invoke(string_view operation, CompressBatch compressBatch)
{
_observer.attach(_instance.get(), operation);
_instance->outgoingConnectionFactory()->flushAsyncBatchRequests(shared_from_this(), compressBatch);
Expand Down Expand Up @@ -377,13 +377,6 @@ Ice::CommunicatorI::postToClientThreadPool(function<void()> call)
_instance->clientThreadPool()->dispatch(call);
}

namespace
{

const ::std::string flushBatchRequests_name = "flushBatchRequests";

}

::std::function<void()>
Ice::CommunicatorI::flushBatchRequestsAsync(CompressBatch compress,
function<void(exception_ptr)> ex,
Expand All @@ -401,7 +394,8 @@ Ice::CommunicatorI::flushBatchRequestsAsync(CompressBatch compress,
}
};
auto outAsync = make_shared<CommunicatorFlushBatchLambda>(_instance, ex, sent);
outAsync->invoke(flushBatchRequests_name, compress);
static constexpr string_view operationName = "flushBatchRequests";
outAsync->invoke(operationName, compress);
return [outAsync]() { outAsync->cancel(); };
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/CommunicatorI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CommunicatorFlushBatchAsync : public OutgoingAsyncBase
CommunicatorFlushBatchAsync(const InstancePtr&);

void flushConnection(const Ice::ConnectionIPtr&, Ice::CompressBatch);
void invoke(const std::string&, Ice::CompressBatch);
void invoke(std::string_view, Ice::CompressBatch);

std::shared_ptr<CommunicatorFlushBatchAsync> shared_from_this()
{
Expand Down
18 changes: 8 additions & 10 deletions cpp/src/Ice/ConnectionI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ using namespace IceInternal;
namespace
{

const ::std::string flushBatchRequests_name = "flushBatchRequests";

class TimeoutCallback final : public IceUtil::TimerTask
{
public:
Expand Down Expand Up @@ -139,7 +137,7 @@ class ConnectionFlushBatchAsync : public OutgoingAsyncBase

virtual Ice::ConnectionPtr getConnection() const;

void invoke(const std::string&, Ice::CompressBatch);
void invoke(std::string_view, Ice::CompressBatch);

private:

Expand Down Expand Up @@ -171,7 +169,7 @@ ConnectionFlushBatchAsync::getConnection() const
}

void
ConnectionFlushBatchAsync::invoke(const string& operation, Ice::CompressBatch compressBatch)
ConnectionFlushBatchAsync::invoke(string_view operation, Ice::CompressBatch compressBatch)
{
_observer.attach(_instance.get(), operation);
try
Expand Down Expand Up @@ -791,15 +789,14 @@ Ice::ConnectionI::flushBatchRequestsAsync(CompressBatch compress,
}
};
auto outAsync = make_shared<ConnectionFlushBatchLambda>(shared_from_this(), _instance, ex, sent);
outAsync->invoke(flushBatchRequests_name, compress);
static constexpr string_view operationName = "flushBatchRequests";
outAsync->invoke(operationName, compress);
return [outAsync]() { outAsync->cancel(); };
}

namespace
{

const string heartbeat_name = "heartbeat";

class HeartbeatAsync : public OutgoingAsyncBase
{
public:
Expand All @@ -823,14 +820,14 @@ class HeartbeatAsync : public OutgoingAsyncBase
return _connection;
}

virtual const string& getOperation() const
virtual string_view getOperation() const
{
return heartbeat_name;
return _operationName;
}

void invoke()
{
_observer.attach(_instance.get(), heartbeat_name);
_observer.attach(_instance.get(), _operationName);
try
{
_os.write(magic[0]);
Expand Down Expand Up @@ -874,6 +871,7 @@ class HeartbeatAsync : public OutgoingAsyncBase

CommunicatorPtr _communicator;
ConnectionIPtr _connection;
static constexpr string_view _operationName = "heartbeat";
};

}
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/Ice/InstrumentationI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class InvocationHelper : public MetricsHelperT<InvocationMetrics>
}
};
static Attributes attributes;
InvocationHelper(const optional<ObjectPrx>& proxy, const string& op, const Context& ctx) :
InvocationHelper(const optional<ObjectPrx>& proxy, string_view op, const Context& ctx) :
_proxy(proxy), _operation(op), _context(ctx)
{
}
Expand Down Expand Up @@ -472,7 +472,7 @@ class InvocationHelper : public MetricsHelperT<InvocationMetrics>
}
}

const string&
string_view
getOperation() const
{
return _operation;
Expand All @@ -481,7 +481,7 @@ class InvocationHelper : public MetricsHelperT<InvocationMetrics>
private:

const optional<ObjectPrx>& _proxy;
const string& _operation;
string_view _operation;
const Context& _context;
mutable string _id;
};
Expand Down Expand Up @@ -1024,7 +1024,7 @@ CommunicatorObserverI::getThreadObserver(const string& parent,
}

InvocationObserverPtr
CommunicatorObserverI::getInvocationObserver(const optional<ObjectPrx>& proxy, const string& op, const Context& ctx)
CommunicatorObserverI::getInvocationObserver(const optional<ObjectPrx>& proxy, string_view op, const Context& ctx)
{
if(_invocations.isEnabled())
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/InstrumentationI.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class ICE_API CommunicatorObserverI : public Ice::Instrumentation::CommunicatorO
const Ice::Instrumentation::ThreadObserverPtr&);

virtual Ice::Instrumentation::InvocationObserverPtr getInvocationObserver(const std::optional<Ice::ObjectPrx>&,
const std::string&,
std::string_view,
const Ice::Context&);

virtual Ice::Instrumentation::DispatchObserverPtr getDispatchObserver(const Ice::Current&, std::int32_t);
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/LoggerAdminI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class LoggerAdminI : public Ice::LoggerAdmin,

vector<RemoteLoggerPrx> log(const LogMessage&);

void deadRemoteLogger(const RemoteLoggerPrx&, const LoggerPtr&, exception_ptr, const string&);
void deadRemoteLogger(const RemoteLoggerPrx&, const LoggerPtr&, exception_ptr, std::string_view);

int getTraceLevel() const
{
Expand Down Expand Up @@ -548,7 +548,7 @@ void
LoggerAdminI::deadRemoteLogger(const RemoteLoggerPrx& remoteLogger,
const LoggerPtr& logger,
std::exception_ptr ex,
const string& operation)
string_view operation)
{
//
// No need to convert remoteLogger as we only use its identity
Expand Down
Loading

0 comments on commit 1762a96

Please sign in to comment.