Skip to content

Commit

Permalink
More clan-tidy leftovers
Browse files Browse the repository at this point in the history
Summary: More clang-tidy warnings...

Reviewed By: kiminoue7

Differential Revision: D52824643
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Jan 17, 2024
1 parent 7e06027 commit eebd72c
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 38 deletions.
12 changes: 8 additions & 4 deletions vrs/DataPieceTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ using std::size_t;
/// https://stackoverflow.com/questions/17794569/why-isnt-vectorbool-a-stl-container
class Bool {
public:
/*implicit*/ Bool(bool value = false) : value_(value) {}
// NOLINTNEXTLINE(hicpp-explicit-conversions)
Bool(bool value = false) : value_(value) {}
Bool& operator=(bool value) {
value_ = value;
return *this;
}
/*implicit*/ operator bool() const {
// NOLINTNEXTLINE(hicpp-explicit-conversions)
operator bool() const {
return value_;
}
const bool* operator&() const {
Expand Down Expand Up @@ -77,7 +79,8 @@ struct PointND {
static constexpr size_t kSize = N;

PointND() : dim{} {}
/*implicit*/ PointND(const T arr[N]) {
// NOLINTNEXTLINE(hicpp-explicit-conversions)
PointND(const T arr[N]) {
operator=(arr);
}

Expand Down Expand Up @@ -179,7 +182,8 @@ struct MatrixND {
static constexpr size_t kMatrixSize = N;

MatrixND() = default;
/*implicit*/ MatrixND(const T arr[N][N]) {
// NOLINTNEXTLINE(hicpp-explicit-conversions)
MatrixND(const T arr[N][N]) {
operator=(arr);
}

Expand Down
4 changes: 2 additions & 2 deletions vrs/DataReference.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DataReference {
/// @param data: Pointer to second block of bytes.
/// @param size: Size of second block of bytes.
template <class T>
DataReference(vector<T>& vectorT, void* data = nullptr, uint32_t size = 0)
explicit DataReference(vector<T>& vectorT, void* data = nullptr, uint32_t size = 0)
: DataReference(
vectorT.data(),
static_cast<uint32_t>(sizeof(T) * vectorT.size()),
Expand Down Expand Up @@ -104,7 +104,7 @@ class DataReference {
/// @param data: Pointer to second block of bytes.
/// @param size: Size of second block of bytes.
template <class T>
DataReference(T& object, void* data = nullptr, uint32_t size = 0)
explicit DataReference(T& object, void* data = nullptr, uint32_t size = 0)
: DataReference(&object, sizeof(T), data, size) {}

/// @param data1: Pointer to first block of bytes.
Expand Down
6 changes: 4 additions & 2 deletions vrs/DataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class DataSourceChunk {
DataSourceChunk(const void* _data, size_t _size);
/// Constructor for a vector<T> of objects of POD type T.
template <typename T>
/* implicit */ DataSourceChunk(const vector<T>& vectorT)
// NOLINTNEXTLINE(hicpp-explicit-conversions)
DataSourceChunk(const vector<T>& vectorT)
: data_{vectorT.data()}, size_{sizeof(T) * vectorT.size()} {}
virtual ~DataSourceChunk() = default;

Expand All @@ -89,7 +90,8 @@ class DataSourceChunk {
std::enable_if_t<std::is_trivially_copyable<T>::value, int> = 0,
// T may not be a pointer.
typename = typename enable_if<!is_pointer<T>::value, T>::type>
/* implicit */ DataSourceChunk(const T& object) : data_{&object}, size_{sizeof(T)} {}
// NOLINTNEXTLINE(hicpp-explicit-conversions)
DataSourceChunk(const T& object) : data_{&object}, size_{sizeof(T)} {}

/// Copy the data (if any), and update the provided buffer pointer accordingly.
/// The number of bytes copied *must be the exact size* specified in the constructor.
Expand Down
1 change: 1 addition & 0 deletions vrs/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Record final {

/// Public for testing
struct uninitialized_byte final {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init, modernize-use-equals-default)
uninitialized_byte() {} // do not use '= default' as it will initialize byte!
uint8_t byte;
};
Expand Down
20 changes: 7 additions & 13 deletions vrs/RecordFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,9 @@ struct CompressionThreadsData {
// structure holding the background save thread's data, if any
struct WriterThreadData {
WriterThreadData()
: fileError{0},
shouldEndThread{false},
writeEventChannel{
: writeEventChannel{
"WriterThreadDataWriteEventChannel",
os::EventChannel::NotificationMode::UNICAST},
hasRecordsReadyToWrite{false},
maxTimestampProvider{nullptr},
autoCollectDelay{0},
nextAutoCollectTime{0} {
os::EventChannel::NotificationMode::UNICAST} {
// Do *not* start the thread here, as this will create race conditions.
// The thread may start before the constructor even finished and returned, which means the
// main thread may not even have a reference to this object.
Expand All @@ -168,15 +162,15 @@ struct WriterThreadData {
}
}

atomic<int> fileError; // 0, or last write error
atomic<bool> shouldEndThread; // set when this thread should finish-up & end
atomic<int> fileError{}; // 0, or last write error
atomic<bool> shouldEndThread{}; // set when this thread should finish-up & end
os::EventChannel writeEventChannel; // wake the background thread to write prepared records

recursive_mutex mutex; // mutex to protect access to the following fields
RecordFileWriter::RecordBatches recordsReadyToWrite;
atomic<bool> hasRecordsReadyToWrite;
RecordFileWriter::RecordBatches recordsReadyToWrite{};
atomic<bool> hasRecordsReadyToWrite{};
function<double()> maxTimestampProvider; // for auto-writing records
atomic<double> autoCollectDelay; // for auto-writing records
atomic<double> autoCollectDelay{}; // for auto-writing records
double nextAutoCollectTime{}; // for auto-writing records

CompressionThreadsData compressionThreadsData_;
Expand Down
13 changes: 13 additions & 0 deletions vrs/RecordFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class ImageContentBlockSpec {
uint32_t keyFrameIndex = 0);

/// Image formats with encoding (png, jpeg, etc).
// NOLINTNEXTLINE(hicpp-explicit-conversions)
ImageContentBlockSpec(ImageFormat imageFormat, uint32_t width = 0, uint32_t height = 0);

/// Raw pixels image formats.
Expand Down Expand Up @@ -343,6 +344,7 @@ class AudioContentBlockSpec {
/// For audio formats with encoding (mp3, flac, etc).
explicit AudioContentBlockSpec(AudioFormat audioFormat, uint8_t channelCount = 0);
/// For PCM audio formats.
// NOLINTNEXTLINE(hicpp-explicit-conversions)
AudioContentBlockSpec(
AudioSampleFormat sampleFormat,
uint8_t channelCount = 0,
Expand Down Expand Up @@ -479,12 +481,14 @@ class ContentBlock {
static const size_t kSizeUnknown;

/// Very generic block description.
// NOLINTNEXTLINE(hicpp-explicit-conversions)
ContentBlock(ContentType type = ContentType::EMPTY, size_t size = kSizeUnknown);

/// Factory-style reconstruct from persisted description as string on disk.
explicit ContentBlock(const string& formatStr);

/// Image formats with encoding (png, jpeg, etc).
// NOLINTNEXTLINE(hicpp-explicit-conversions)
ContentBlock(ImageFormat imageFormat, uint32_t width = 0, uint32_t height = 0);

/// Image formats with custom codec encoding.
Expand All @@ -505,16 +509,19 @@ class ContentBlock {
uint32_t stride = 0,
uint32_t stride2 = 0);

// NOLINTNEXTLINE(hicpp-explicit-conversions)
ContentBlock(const ImageContentBlockSpec& imageSpec, size_t size = kSizeUnknown);
ContentBlock(
const ContentBlock& imageContentBlock,
double keyFrameTimestamp,
uint32_t keyFrameIndex);

/// Very generic audio block description.
// NOLINTNEXTLINE(hicpp-explicit-conversions)
ContentBlock(AudioFormat audioFormat, uint8_t channelCount = 0);

/// PCM audio block description.
// NOLINTNEXTLINE(hicpp-explicit-conversions)
ContentBlock(
AudioSampleFormat sampleFormat,
uint8_t numChannels = 0,
Expand Down Expand Up @@ -645,25 +652,30 @@ class RecordFormat {
/// Empty record format definition.
RecordFormat() = default;
/// Default copy constructor
// NOLINTNEXTLINE(hicpp-explicit-conversions)
RecordFormat(const RecordFormat&) = default;

/// Build a RecordFormat from a string description.
/// This constructor is meant for internal VRS usage only.
/// @internal
// NOLINTNEXTLINE(hicpp-explicit-conversions)
RecordFormat(const string& format) {
set(format);
}
/// Build a RecordFormat from a string description.
/// This constructor is meant for internal VRS usage only.
/// @internal
// NOLINTNEXTLINE(hicpp-explicit-conversions)
RecordFormat(const char* format) {
set(format);
}
/// Build a RecordFormat from a single ContentBlock.
// NOLINTNEXTLINE(hicpp-explicit-conversions)
RecordFormat(const ContentBlock& block) {
blocks_.emplace_back(block);
}
/// Build a RecordFormat from a single ContentBlock.
// NOLINTNEXTLINE(hicpp-explicit-conversions)
RecordFormat(ContentBlock&& block) {
blocks_.emplace_back(block);
}
Expand All @@ -681,6 +693,7 @@ class RecordFormat {
/// @param type: Content type of the block.
/// @param size: Size of the block, or ContentBlock::kSizeUnknown, if the size of the block isn't
/// known/fixed.
// NOLINTNEXTLINE(hicpp-explicit-conversions)
RecordFormat(ContentType type, size_t size = ContentBlock::kSizeUnknown) {
blocks_.emplace_back(type, size);
}
Expand Down
1 change: 1 addition & 0 deletions vrs/helpers/MemBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace helpers {

class MemBuffer {
struct uninitialized_byte final {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init, modernize-use-equals-default)
uninitialized_byte() {} // do not use '= default' as it will initialize byte!
uint8_t byte;
};
Expand Down
2 changes: 2 additions & 0 deletions vrs/helpers/Rapidjson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ using JValue = vrs_rapidjson::GenericValue<JUtf8Encoding, JCrtAllocator>;
using JStringRef = vrs_rapidjson::GenericStringRef<char>;

static inline JStringRef jStringRef(const char* str) {
// NOLINTNEXTLINE(modernize-return-braced-init-list)
return JStringRef(str, strlen(str));
}
static inline JStringRef jStringRef(const string& str) {
// NOLINTNEXTLINE(modernize-return-braced-init-list)
return JStringRef(str.c_str(), str.size());
}
template <class T>
Expand Down
1 change: 1 addition & 0 deletions vrs/test/DataLayoutFormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ TEST_F(DataLayoutFormatTester, DataLayoutFormatTest) {
os::remove(fileName);
}

// NOLINTNEXTLINE(modernize-macro-to-enum)
#define SAMPLE_EPOCH_TIME 2000000000

TEST_F(DataLayoutFormatTester, FormatValuesTest) {
Expand Down
1 change: 1 addition & 0 deletions vrs/test/RecordTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ static uint8_t f(uint8_t k) {
const size_t kSize = 9; // odd, to expose padding issues

union ArrayUnion {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
ArrayUnion() {} // required, do not use '= default' which would initialize the fields!
Record::uninitialized_byte uninitialized_bytes[kSize];
uint8_t initialized_bytes[kSize];
Expand Down
5 changes: 3 additions & 2 deletions vrs/utils/AudioExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <array>
#include <iostream>
#include <utility>

#define DEFAULT_LOG_CHANNEL "AudioExtractor"
#include <logging/Log.h>
Expand Down Expand Up @@ -136,8 +137,8 @@ int AudioExtractor::closeWavFile(DiskFile& inFile) {
return inFile.close();
}

AudioExtractor::AudioExtractor(const string& folderPath, StreamId id, uint32_t& counter)
: folderPath_{folderPath},
AudioExtractor::AudioExtractor(string folderPath, StreamId id, uint32_t& counter)
: folderPath_{std::move(folderPath)},
id_{id},
cumulativeOutputAudioFileCount_{counter},
currentAudioContentBlockSpec_{AudioFormat::UNDEFINED} {}
Expand Down
2 changes: 1 addition & 1 deletion vrs/utils/AudioExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace vrs::utils {

class AudioExtractor : public RecordFormatStreamPlayer {
public:
AudioExtractor(const string& folderPath, StreamId id, uint32_t& counter);
AudioExtractor(string folderPath, StreamId id, uint32_t& counter);

~AudioExtractor() override;

Expand Down
8 changes: 5 additions & 3 deletions vrs/utils/AudioTrackExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "AudioTrackExtractor.h"

#include <iostream>
#include <limits>
#include <utility>

#define DEFAULT_LOG_CHANNEL "AudioTrackExtractor"
#include <logging/Log.h>
Expand All @@ -37,8 +37,10 @@ using namespace vrs::helpers;

namespace vrs::utils {

AudioTrackExtractor::AudioTrackExtractor(const string& wavFilePath, bool& outStop)
: wavFilePath_{wavFilePath}, stop_{outStop}, fileAudioSpec_{AudioFormat::UNDEFINED} {}
AudioTrackExtractor::AudioTrackExtractor(string wavFilePath, bool& outStop)
: wavFilePath_{std::move(wavFilePath)},
stop_{outStop},
fileAudioSpec_{AudioFormat::UNDEFINED} {}

AudioTrackExtractor::~AudioTrackExtractor() {
AudioExtractor::closeWavFile(wavFile_);
Expand Down
2 changes: 1 addition & 1 deletion vrs/utils/AudioTrackExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace vrs::utils {

class AudioTrackExtractor : public RecordFormatStreamPlayer {
public:
AudioTrackExtractor(const string& wavFilePath, bool& outStop);
AudioTrackExtractor(string wavFilePath, bool& outStop);
~AudioTrackExtractor() override;

bool onAudioRead(const CurrentRecord& record, size_t, const ContentBlock& audioBlock) override;
Expand Down
6 changes: 4 additions & 2 deletions vrs/utils/DataExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "DataExtractor.h"

#include <utility>

#include <fmt/format.h>

#define DEFAULT_LOG_CHANNEL "DataExtractor"
Expand All @@ -39,8 +41,8 @@ using namespace vrs;

DataExtractor::DataExtractorStreamPlayer::DataExtractorStreamPlayer(
ofstream& output,
const string& outputFolder)
: output_{output}, outputFolder_{outputFolder} {}
string outputFolder)
: output_{output}, outputFolder_{std::move(outputFolder)} {}

bool DataExtractor::DataExtractorStreamPlayer::writeImage(
const CurrentRecord& record,
Expand Down
2 changes: 1 addition & 1 deletion vrs/utils/DataExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DataExtractor {

class DataExtractorStreamPlayer : public utils::VideoRecordFormatStreamPlayer {
public:
DataExtractorStreamPlayer(std::ofstream& output, const string& outputFolder);
DataExtractorStreamPlayer(std::ofstream& output, string outputFolder);
bool onDataLayoutRead(const CurrentRecord&, size_t blockIndex, DataLayout&) override;
bool onImageRead(const CurrentRecord&, size_t blockIndex, const ContentBlock&) override;
bool onAudioRead(const CurrentRecord& record, size_t, const ContentBlock& audioBlock) override;
Expand Down
5 changes: 3 additions & 2 deletions vrs/utils/FilterCopyHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ struct TagOverrider {

// Optional parameters for copy (or merge) operations, to override defaults
struct CopyOptions {
CopyOptions(bool showProgress = true) : showProgress{showProgress} {}
CopyOptions() = default;
explicit CopyOptions(bool showProgress) : showProgress{showProgress} {}
CopyOptions(const CopyOptions& rhs);

// Compression preset of the output file. Use this method to set the user's explicit choice.
Expand Down Expand Up @@ -164,7 +165,7 @@ class ContentBlockChunk : public ContentChunk {

class FilteredChunksSource : public DataSource {
public:
FilteredChunksSource(deque<unique_ptr<ContentChunk>>& chunks)
explicit FilteredChunksSource(deque<unique_ptr<ContentChunk>>& chunks)
: DataSource(getFilteredChunksSize(chunks)), chunks_{chunks} {}
void copyTo(uint8_t* buffer) const override;

Expand Down
2 changes: 1 addition & 1 deletion vrs/utils/ThrottleHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ThrottledFileDelegate;
/// using a RecordFileWriter object.
class ThrottledWriter {
public:
ThrottledWriter(const CopyOptions& options);
explicit ThrottledWriter(const CopyOptions& options);
ThrottledWriter(const CopyOptions& options, ThrottledFileDelegate& fileDelegate);

/// Init writer with latest copy options values (if they were changed since constructor)
Expand Down
4 changes: 1 addition & 3 deletions vrs/utils/Validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,7 @@ class RecordMaster : public StreamPlayer {
id_{matchingId},
reader_{matchingReader},
holder_{holder},
index_{reader_.getIndex(id_)},
lastRecord_{0},
readCounter_{0} {}
index_{reader_.getIndex(id_)} {}
bool processRecordHeader(const CurrentRecord& record, DataReference& outDataReference) override {
buffer_.resize(record.recordSize);
outDataReference.useVector(buffer_);
Expand Down
2 changes: 1 addition & 1 deletion vrs/utils/converters/Raw10ToGrey10Converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void convertVectorized(
if (contiguous) {
const int numFullOperations = (heightInPixels * widthInPixels) / 8;
// The width must be a multiple of 4, so there is at most one leftover pixel group.
bool hasLeftover = (heightInPixels * widthInPixels) % 8 ? true : false;
bool hasLeftover = (heightInPixels * widthInPixels) % 8;
for (int op = 0; op < numFullOperations; ++op) {
const uint8x16_t encoded = vld1q_u8(src);
const uint8x16_t r = vqtbl1q_u8(encoded, rshuf);
Expand Down

0 comments on commit eebd72c

Please sign in to comment.