Commit f121101a authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook GitHub Bot

update AsyncLogWriter::performIO() to take the vector by reference

Summary:
Update the `AsyncLogWriter::performIO()` API to take the vector of messages by
const reference, rather than by modifiable pointer.  This parameter is purely
an input parameter, and shouldn't be modified by the `performIO()` code, so it
makes more sense to take this as const reference.

Differential Revision: D21367425

fbshipit-source-id: 4bbf3a58dd48bb620101ec3982b189bea656b301
parent 439c7b22
......@@ -36,7 +36,7 @@ bool AsyncFileWriter::ttyOutput() const {
}
void AsyncFileWriter::writeToFile(
std::vector<std::string>* ioQueue,
const std::vector<std::string>& ioQueue,
size_t numDiscarded) {
// kNumIovecs controls the maximum number of strings we write at once in a
// single writev() call.
......@@ -44,10 +44,10 @@ void AsyncFileWriter::writeToFile(
std::array<iovec, kNumIovecs> iovecs;
size_t idx = 0;
while (idx < ioQueue->size()) {
while (idx < ioQueue.size()) {
int numIovecs = 0;
while (numIovecs < kNumIovecs && idx < ioQueue->size()) {
const auto& str = (*ioQueue)[idx];
while (numIovecs < kNumIovecs && idx < ioQueue.size()) {
const auto& str = ioQueue[idx];
iovecs[numIovecs].iov_base = const_cast<char*>(str.data());
iovecs[numIovecs].iov_len = str.size();
++numIovecs;
......@@ -70,7 +70,7 @@ void AsyncFileWriter::writeToFile(
}
void AsyncFileWriter::performIO(
std::vector<std::string>* ioQueue,
const std::vector<std::string>& ioQueue,
size_t numDiscarded) {
try {
writeToFile(ioQueue, numDiscarded);
......
......@@ -55,9 +55,11 @@ class AsyncFileWriter : public AsyncLogWriter {
}
private:
void writeToFile(std::vector<std::string>* ioQueue, size_t numDiscarded);
void writeToFile(
const std::vector<std::string>& ioQueue,
size_t numDiscarded);
void performIO(std::vector<std::string>* ioQueue, size_t numDiscarded)
void performIO(const std::vector<std::string>& ioQueue, size_t numDiscarded)
override;
std::string getNumDiscardedMsg(size_t numDiscarded);
......
......@@ -78,7 +78,7 @@ void AsyncLogWriter::cleanup() {
// If there are still any pending messages, flush them now.
if (!ioQueue->empty()) {
performIO(ioQueue, numDiscarded);
performIO(*ioQueue, numDiscarded);
}
}
......@@ -169,7 +169,7 @@ void AsyncLogWriter::ioThread() {
ioCV_.notify_all();
// Write the log messages now that we have released the lock
performIO(ioQueue, numDiscarded);
performIO(*ioQueue, numDiscarded);
// clear() empties the vector, but the allocated capacity remains so we can
// just reuse it without having to re-allocate in most cases.
......
......@@ -136,7 +136,7 @@ class AsyncLogWriter : public LogWriter {
* messages. This method will be called in a separate IO thread.
*/
virtual void performIO(
std::vector<std::string>* logs,
const std::vector<std::string>& logs,
size_t numDiscarded) = 0;
void ioThread();
......
......@@ -38,7 +38,7 @@ void handleLoggingError(
}
class NoCleanUpLogWriter : public AsyncLogWriter {
void performIO(std::vector<std::string>*, size_t) override {}
void performIO(const std::vector<std::string>&, size_t) override {}
bool ttyOutput() const override {
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment