Skip to content

Commit a86783e

Browse files
authored
use iostream instead of printf (#977)
* use iostream instead of printf * fixes from PR, add reserve to strings
1 parent 9b5b933 commit a86783e

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

ydb/core/base/logoblob.cpp

+14-23
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
#include "logoblob.h"
22
#include <ydb/core/protos/base.pb.h>
3-
#include <util/string/printf.h>
43

54
namespace NKikimr {
65

76
TString TLogoBlobID::ToString() const {
8-
return Sprintf(
9-
"[%" PRIu64 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 "]",
10-
TabletID(),
11-
Generation(),
12-
Step(),
13-
Channel(),
14-
Cookie(),
15-
BlobSize(),
16-
PartId()).data();
7+
TString str;
8+
str.reserve(64);
9+
TStringOutput outStr(str);
10+
Out(outStr);
11+
return str;
1712
}
1813

1914
void TLogoBlobID::Out(IOutputStream &o) const {
20-
char buf[240];
21-
snprintf(buf, sizeof(buf),
22-
"[%" PRIu64 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 "]",
23-
TabletID(),
24-
Generation(),
25-
Step(),
26-
Channel(),
27-
Cookie(),
28-
BlobSize(),
29-
PartId()
30-
);
31-
32-
o << buf;
15+
o << '['
16+
<< TabletID() << ':'
17+
<< Generation() << ':'
18+
<< Step() << ':'
19+
<< Channel() << ':'
20+
<< Cookie() << ':'
21+
<< BlobSize() << ':'
22+
<< PartId()
23+
<< ']' ;
3324
}
3425

3526
void TLogoBlobID::Out(IOutputStream &o, const TVector<TLogoBlobID> &vec) {

ydb/core/base/traceid.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ TTraceID TTraceID::GenerateNew() {
2020
}
2121

2222
TString TTraceID::ToString() const {
23-
TString result;
24-
TStringOutput out(result);
25-
Out(out);
26-
return result;
23+
TString str;
24+
str.reserve(128);
25+
TStringOutput outStr(str);
26+
Out(outStr);
27+
return str;
2728
}
2829

2930
void TTraceID::Out(IOutputStream &o) const {
30-
char buf[240];
31-
snprintf(buf, sizeof(buf), "[ID:%" PRIu64 ", Created: %s]", RandomID, TInstant::MicroSeconds(CreationTime).ToRfc822StringLocal().data());
32-
o << buf;
31+
o << "[ID: " << RandomID << ", " << "Created: " << TInstant::MicroSeconds(CreationTime).ToRfc822StringLocal() << "]";
3332
}
3433

3534
bool TTraceID::operator<(const TTraceID &x) const {

0 commit comments

Comments
 (0)