Skip to content

Commit 1289dcb

Browse files
committed
(WIP) Add performance check
1 parent 537f13b commit 1289dcb

File tree

98 files changed

+520
-542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+520
-542
lines changed

.clang-tidy

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,77 +16,25 @@
1616
# under the License.
1717

1818
---
19-
#bugprone-*,
20-
#google-*,
21-
#misc-*,
22-
#modernize-*,
23-
#performance-*,
24-
#portability-*,
25-
#readability-*,
26-
#-google-readability-braces-around-statements,
27-
#-google-readability-namespace-comments,
28-
#-google-runtime-references,
29-
#-misc-non-private-member-variables-in-classes,
30-
#-misc-const-correctness,
31-
#-misc-include-cleaner,
32-
#-modernize-return-braced-init-list,
33-
#-modernize-use-trailing-return-type,
34-
#-modernize-concat-nested-namespaces,
35-
#-modernize-use-nodiscard,
36-
#-modernize-avoid-c-arrays,
37-
#-modernize-type-traits,
38-
#-modernize-unary-static-assert,
39-
#-performance-move-const-arg,
40-
#-performance-avoid-endl,
41-
#-performance-enum-size,
42-
#-readability-braces-around-statements,
43-
#-readability-identifier-length,
44-
#-readability-magic-numbers,
45-
#-readability-named-parameter,
46-
#-readability-redundant-declaration,
47-
#-readability-avoid-return-with-void-value,
48-
#-readability-function-cognitive-complexity,
49-
#-bugprone-narrowing-conversions,
50-
#-bugprone-easily-swappable-parameters,
51-
#-bugprone-inc-dec-in-conditions,
52-
#-bugprone-implicit-widening-of-multiplication-result,
53-
#-bugprone-unchecked-optional-access,
54-
#-bugprone-unused-local-non-trivial-variable,
55-
#-bugprone-unused-return-value,
56-
#-bugprone-reserved-identifier,
57-
#-google-build-using-namespace,
58-
#-misc-unused-parameters,
59-
#-modernize-deprecated-headers,
60-
#-modernize-use-equals-default,
61-
#-modernize-use-using,
62-
#-readability-enum-initial-value,
19+
# TODO: add more checks
20+
# - bugprone
21+
# - cppcoreguidelines
22+
# - portability
23+
# - readability
6324
Checks: >
6425
-*,
6526
clang-analyzer-*,
6627
-clang-analyzer-security.insecureAPI.rand,
28+
performance-*,
29+
-performance-inefficient-string-concatenation
6730
WarningsAsErrors: '*'
6831
HeaderFileExtensions:
6932
- ''
7033
- h
7134
ImplementationFileExtensions:
7235
- cc
73-
HeaderFilterRegex: '.*'
36+
HeaderFilterRegex: '^(?!.*PulsarApi\.pb\.h$).*$'
7437
FormatStyle: none
7538
CheckOptions:
76-
cert-err33-c.CheckedFunctions: '^::aligned_alloc;^::asctime_s;^::at_quick_exit;^::atexit;^::bsearch;^::bsearch_s;^::btowc;^::c16rtomb;^::c32rtomb;^::calloc;^::clock;^::cnd_broadcast;^::cnd_init;^::cnd_signal;^::cnd_timedwait;^::cnd_wait;^::ctime_s;^::fclose;^::fflush;^::fgetc;^::fgetpos;^::fgets;^::fgetwc;^::fopen;^::fopen_s;^::fprintf;^::fprintf_s;^::fputc;^::fputs;^::fputwc;^::fputws;^::fread;^::freopen;^::freopen_s;^::fscanf;^::fscanf_s;^::fseek;^::fsetpos;^::ftell;^::fwprintf;^::fwprintf_s;^::fwrite;^::fwscanf;^::fwscanf_s;^::getc;^::getchar;^::getenv;^::getenv_s;^::gets_s;^::getwc;^::getwchar;^::gmtime;^::gmtime_s;^::localtime;^::localtime_s;^::malloc;^::mbrtoc16;^::mbrtoc32;^::mbsrtowcs;^::mbsrtowcs_s;^::mbstowcs;^::mbstowcs_s;^::memchr;^::mktime;^::mtx_init;^::mtx_lock;^::mtx_timedlock;^::mtx_trylock;^::mtx_unlock;^::printf_s;^::putc;^::putwc;^::raise;^::realloc;^::remove;^::rename;^::scanf;^::scanf_s;^::setlocale;^::setvbuf;^::signal;^::snprintf;^::snprintf_s;^::sprintf;^::sprintf_s;^::sscanf;^::sscanf_s;^::strchr;^::strerror_s;^::strftime;^::strpbrk;^::strrchr;^::strstr;^::strtod;^::strtof;^::strtoimax;^::strtok;^::strtok_s;^::strtol;^::strtold;^::strtoll;^::strtoul;^::strtoull;^::strtoumax;^::strxfrm;^::swprintf;^::swprintf_s;^::swscanf;^::swscanf_s;^::thrd_create;^::thrd_detach;^::thrd_join;^::thrd_sleep;^::time;^::timespec_get;^::tmpfile;^::tmpfile_s;^::tmpnam;^::tmpnam_s;^::tss_create;^::tss_get;^::tss_set;^::ungetc;^::ungetwc;^::vfprintf;^::vfprintf_s;^::vfscanf;^::vfscanf_s;^::vfwprintf;^::vfwprintf_s;^::vfwscanf;^::vfwscanf_s;^::vprintf_s;^::vscanf;^::vscanf_s;^::vsnprintf;^::vsnprintf_s;^::vsprintf;^::vsprintf_s;^::vsscanf;^::vsscanf_s;^::vswprintf;^::vswprintf_s;^::vswscanf;^::vswscanf_s;^::vwprintf_s;^::vwscanf;^::vwscanf_s;^::wcrtomb;^::wcschr;^::wcsftime;^::wcspbrk;^::wcsrchr;^::wcsrtombs;^::wcsrtombs_s;^::wcsstr;^::wcstod;^::wcstof;^::wcstoimax;^::wcstok;^::wcstok_s;^::wcstol;^::wcstold;^::wcstoll;^::wcstombs;^::wcstombs_s;^::wcstoul;^::wcstoull;^::wcstoumax;^::wcsxfrm;^::wctob;^::wctrans;^::wctype;^::wmemchr;^::wprintf_s;^::wscanf;^::wscanf_s;'
77-
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: 'true'
78-
cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted: 'true'
7939
performance-move-const-arg.CheckTriviallyCopyableMove: 'false'
80-
readability-identifier-naming.LocalVariableCase: 'camelBack'
81-
readability-identifier-naming.LocalConstantCase: 'camelBack'
82-
readability-identifier-naming.StructCase: 'CamelCase'
83-
readability-identifier-naming.ClassCase: 'CamelCase'
84-
readability-identifier-naming.ParameterCase: 'camelBack'
85-
readability-identifier-naming.MethodCase: 'camelBack'
86-
readability-identifier-naming.EnumCase: 'CamelCase'
87-
readability-identifier-naming.FunctionCase: 'camelBack'
88-
readability-identifier-naming.MemberCase: 'camelBack'
89-
readability-identifier-naming.PrivateMemberSuffix: '_'
90-
readability-identifier-naming.ProtectedMemberSuffix: '_'
91-
readability-identifier-naming.PublicMemberSuffix: ''
9240
SystemHeaders: false

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ else() # GCC or Clang are mostly compatible:
9797
# Options unique to Clang or GCC:
9898
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
9999
add_compile_options(-Qunused-arguments)
100-
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.1))
101-
add_compile_options(-Wno-stringop-truncation)
102100
endif()
103101
endif()
104102

include/pulsar/Authentication.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,7 @@ class PULSAR_PUBLIC AuthAthenz : public Authentication {
394394
// currently mainly works for access token
395395
class Oauth2TokenResult {
396396
public:
397-
enum
398-
{
399-
undefined_expiration = -1
400-
};
397+
static constexpr int undefined_expiration = -1;
401398

402399
Oauth2TokenResult();
403400
~Oauth2TokenResult();

include/pulsar/Client.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class PULSAR_PUBLIC Client {
110110
* @param topic the name of the topic where to produce
111111
* @param conf the customized ProducerConfiguration
112112
*/
113-
void createProducerAsync(const std::string& topic, ProducerConfiguration conf,
113+
void createProducerAsync(const std::string& topic, const ProducerConfiguration& conf,
114114
CreateProducerCallback callback);
115115

116116
/**
@@ -331,7 +331,7 @@ class PULSAR_PUBLIC Client {
331331
* built from a message that already exists
332332
*/
333333
void createTableViewAsync(const std::string& topic, const TableViewConfiguration& conf,
334-
TableViewCallback callBack);
334+
const TableViewCallback& callBack);
335335

336336
/**
337337
* Get the list of partitions for a given topic.
@@ -415,7 +415,7 @@ class PULSAR_PUBLIC Client {
415415
std::function<void(Result, const SchemaInfo&)> callback);
416416

417417
private:
418-
Client(const std::shared_ptr<ClientImpl>);
418+
Client(const std::shared_ptr<ClientImpl>&);
419419

420420
friend class PulsarFriend;
421421
friend class PulsarWrapper;

include/pulsar/ClientConfiguration.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <pulsar/Logger.h>
2424
#include <pulsar/defines.h>
2525

26+
#include <cstdint>
27+
2628
namespace pulsar {
2729
class PulsarWrapper;
2830
struct ClientConfigurationImpl;
@@ -32,7 +34,7 @@ class PULSAR_PUBLIC ClientConfiguration {
3234
~ClientConfiguration();
3335
ClientConfiguration(const ClientConfiguration&);
3436
ClientConfiguration& operator=(const ClientConfiguration&);
35-
enum ProxyProtocol
37+
enum ProxyProtocol : uint8_t
3638
{
3739
SNI = 0
3840
};

include/pulsar/CompressionType.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
#ifndef PULSAR_COMPRESSIONTYPE_H_
2020
#define PULSAR_COMPRESSIONTYPE_H_
2121

22+
#include <cstdint>
23+
2224
namespace pulsar {
23-
enum CompressionType
25+
enum CompressionType : std::uint8_t
2426
{
2527
CompressionNone = 0,
2628
CompressionLZ4 = 1,

include/pulsar/Consumer.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class PULSAR_PUBLIC Consumer {
8383
*
8484
* @param callback the callback to get notified when the operation is complete
8585
*/
86-
void unsubscribeAsync(ResultCallback callback);
86+
void unsubscribeAsync(const ResultCallback& callback);
8787

8888
/**
8989
* Receive a single message.
@@ -134,10 +134,10 @@ class PULSAR_PUBLIC Consumer {
134134
* </p>
135135
* @param ReceiveCallback will be completed when message is available
136136
*/
137-
void receiveAsync(ReceiveCallback callback);
137+
void receiveAsync(const ReceiveCallback& callback);
138138

139139
template <typename T>
140-
void receiveAsync(std::function<void(Result result, const TypedMessage<T>&)> callback,
140+
void receiveAsync(const std::function<void(Result result, const TypedMessage<T>&)>& callback,
141141
typename TypedMessage<T>::Decoder decoder) {
142142
receiveAsync([callback, decoder](Result result, const Message& msg) {
143143
callback(result, TypedMessage<T>{msg, decoder});
@@ -167,7 +167,7 @@ class PULSAR_PUBLIC Consumer {
167167
* </p>
168168
* @param BatchReceiveCallback will be completed when messages are available.
169169
*/
170-
void batchReceiveAsync(BatchReceiveCallback callback);
170+
void batchReceiveAsync(const BatchReceiveCallback& callback);
171171

172172
/**
173173
* Acknowledge the reception of a single message.
@@ -209,7 +209,7 @@ class PULSAR_PUBLIC Consumer {
209209
* @param message the message to acknowledge
210210
* @param callback callback that will be triggered when the message has been acknowledged
211211
*/
212-
void acknowledgeAsync(const Message& message, ResultCallback callback);
212+
void acknowledgeAsync(const Message& message, const ResultCallback& callback);
213213

214214
/**
215215
* Asynchronously acknowledge the reception of a single message.
@@ -220,15 +220,15 @@ class PULSAR_PUBLIC Consumer {
220220
* @param messageId the messageId to acknowledge
221221
* @param callback the callback that is triggered when the message has been acknowledged or not
222222
*/
223-
void acknowledgeAsync(const MessageId& messageId, ResultCallback callback);
223+
void acknowledgeAsync(const MessageId& messageId, const ResultCallback& callback);
224224

225225
/**
226226
* Asynchronously acknowledge the consumption of a list of message.
227227
* @param messageIdList
228228
* @param callback the callback that is triggered when the message has been acknowledged or not
229229
* @return
230230
*/
231-
void acknowledgeAsync(const MessageIdList& messageIdList, ResultCallback callback);
231+
void acknowledgeAsync(const MessageIdList& messageIdList, const ResultCallback& callback);
232232

233233
/**
234234
* Acknowledge the reception of all the messages in the stream up to (and including)
@@ -239,7 +239,7 @@ class PULSAR_PUBLIC Consumer {
239239
*
240240
* Cumulative acknowledge cannot be used when the consumer type is set to ConsumerShared.
241241
*
242-
* It's equivalent to calling asyncAcknowledgeCumulative(const Message&, ResultCallback) and
242+
* It's equivalent to calling asyncAcknowledgeCumulative(const Message&, const ResultCallback&) and
243243
* waiting for the callback to be triggered.
244244
*
245245
* @param message the last message in the stream to acknowledge
@@ -258,8 +258,8 @@ class PULSAR_PUBLIC Consumer {
258258
*
259259
* Cumulative acknowledge cannot be used when the consumer type is set to ConsumerShared.
260260
*
261-
* It is equivalent to calling the asyncAcknowledgeCumulative(const Message&, ResultCallback) method and
262-
* waiting for the callback to be triggered.
261+
* It is equivalent to calling the asyncAcknowledgeCumulative(const Message&, const ResultCallback&)
262+
* method and waiting for the callback to be triggered.
263263
*
264264
* @param messageId the last messageId in the stream to acknowledge
265265
* @return ResultOk if the message is successfully acknowledged. All previously delivered messages for
@@ -277,7 +277,7 @@ class PULSAR_PUBLIC Consumer {
277277
* @param message the message to acknowledge
278278
* @param callback callback that will be triggered when the message has been acknowledged
279279
*/
280-
void acknowledgeCumulativeAsync(const Message& message, ResultCallback callback);
280+
void acknowledgeCumulativeAsync(const Message& message, const ResultCallback& callback);
281281

282282
/**
283283
* Asynchronously acknowledge the reception of all the messages in the stream up to (and
@@ -289,7 +289,7 @@ class PULSAR_PUBLIC Consumer {
289289
* @param messageId the messageId to acknowledge
290290
* @param callback the callback that is triggered when the message has been acknowledged or not
291291
*/
292-
void acknowledgeCumulativeAsync(const MessageId& messageId, ResultCallback callback);
292+
void acknowledgeCumulativeAsync(const MessageId& messageId, const ResultCallback& callback);
293293

294294
/**
295295
* Acknowledge the failure to process a single message.
@@ -364,7 +364,7 @@ class PULSAR_PUBLIC Consumer {
364364
* Asynchronously close the consumer and stop the broker to push more messages
365365
*
366366
*/
367-
void closeAsync(ResultCallback callback);
367+
void closeAsync(const ResultCallback& callback);
368368

369369
/**
370370
* Pause receiving messages via the messageListener, till resumeMessageListener() is called.
@@ -413,7 +413,7 @@ class PULSAR_PUBLIC Consumer {
413413
* @param callback - callback function to get the brokerConsumerStats,
414414
* if result is ResultOk then the brokerConsumerStats will be populated
415415
*/
416-
void getBrokerConsumerStatsAsync(BrokerConsumerStatsCallback callback);
416+
void getBrokerConsumerStatsAsync(const BrokerConsumerStatsCallback& callback);
417417

418418
/**
419419
* Reset the subscription associated with this consumer to a specific message id.
@@ -445,15 +445,15 @@ class PULSAR_PUBLIC Consumer {
445445
* @param messageId
446446
* the message id where to reposition the subscription
447447
*/
448-
virtual void seekAsync(const MessageId& messageId, ResultCallback callback);
448+
virtual void seekAsync(const MessageId& messageId, const ResultCallback& callback);
449449

450450
/**
451451
* Asynchronously reset the subscription associated with this consumer to a specific message publish time.
452452
*
453453
* @param timestamp
454454
* the message publish time where to reposition the subscription
455455
*/
456-
virtual void seekAsync(uint64_t timestamp, ResultCallback callback);
456+
virtual void seekAsync(uint64_t timestamp, const ResultCallback& callback);
457457

458458
/**
459459
* @return Whether the consumer is currently connected to the broker
@@ -464,7 +464,7 @@ class PULSAR_PUBLIC Consumer {
464464
* Asynchronously get an ID of the last available message or a message ID with -1 as an entryId if the
465465
* topic is empty.
466466
*/
467-
void getLastMessageIdAsync(GetLastMessageIdCallback callback);
467+
void getLastMessageIdAsync(const GetLastMessageIdCallback& callback);
468468

469469
/**
470470
* Get an ID of the last available message or a message ID with -1 as an entryId if the topic is empty.

include/pulsar/ConsumerConfiguration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class PULSAR_PUBLIC ConsumerConfiguration {
117117
*
118118
* @param keySharedPolicy The {@link KeySharedPolicy} want to specify
119119
*/
120-
ConsumerConfiguration& setKeySharedPolicy(KeySharedPolicy keySharedPolicy);
120+
ConsumerConfiguration& setKeySharedPolicy(const KeySharedPolicy& keySharedPolicy);
121121

122122
/**
123123
* @return the KeyShared subscription policy

include/pulsar/ConsumerType.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
#ifndef PULSAR_CPP_CONSUMERTYPE_H
2020
#define PULSAR_CPP_CONSUMERTYPE_H
2121

22+
#include <cstdint>
23+
2224
namespace pulsar {
23-
enum ConsumerType
25+
enum ConsumerType : uint8_t
2426
{
2527
/**
2628
* There can be only 1 consumer on the same topic with the same consumerName

include/pulsar/CryptoKeyReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class PULSAR_PUBLIC DefaultCryptoKeyReader : public CryptoKeyReader {
7171
private:
7272
std::string publicKeyPath_;
7373
std::string privateKeyPath_;
74-
void readFile(std::string fileName, std::string& fileContents) const;
74+
void readFile(const std::string& fileName, std::string& fileContents) const;
7575

7676
public:
7777
/**

0 commit comments

Comments
 (0)