Skip to content

Commit

Permalink
Replace most typedef with using= (facebook#8751)
Browse files Browse the repository at this point in the history
Summary:
Old typedef syntax is confusing

Most but not all changes with

    perl -pi -e 's/typedef (.*) ([a-zA-Z0-9_]+);/using $2 = $1;/g' list_of_files
    make format

Pull Request resolved: facebook#8751

Test Plan: existing

Reviewed By: zhichao-cao

Differential Revision: D30745277

Pulled By: pdillinger

fbshipit-source-id: 6f65f0631c3563382d43347896020413cc2366d9
  • Loading branch information
pdillinger authored and facebook-github-bot committed Sep 7, 2021
1 parent 55ef897 commit 4750421
Show file tree
Hide file tree
Showing 59 changed files with 125 additions and 133 deletions.
2 changes: 1 addition & 1 deletion cache/clock_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ struct CleanupContext {
class ClockCacheShard final : public CacheShard {
public:
// Hash map type.
typedef tbb::concurrent_hash_map<CacheKey, CacheHandle*, CacheKey> HashTable;
using HashTable = tbb::concurrent_hash_map<CacheKey, CacheHandle*, CacheKey>;

ClockCacheShard();
~ClockCacheShard() override;
Expand Down
6 changes: 3 additions & 3 deletions db/compaction/compaction_picker_universal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ struct SmallestKeyHeapComparator {
const Comparator* ucmp_;
};

typedef std::priority_queue<InputFileInfo, std::vector<InputFileInfo>,
SmallestKeyHeapComparator>
SmallestKeyHeap;
using SmallestKeyHeap =
std::priority_queue<InputFileInfo, std::vector<InputFileInfo>,
SmallestKeyHeapComparator>;

// This function creates the heap that is used to find if the files are
// overlapping during universal compaction when the allow_trivial_move
Expand Down
2 changes: 1 addition & 1 deletion db/db_impl/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3116,7 +3116,7 @@ SnapshotImpl* DBImpl::GetSnapshotImpl(bool is_write_conflict_boundary,
}

namespace {
typedef autovector<ColumnFamilyData*, 2> CfdList;
using CfdList = autovector<ColumnFamilyData*, 2>;
bool CfdListContains(const CfdList& list, ColumnFamilyData* cfd) {
for (const ColumnFamilyData* t : list) {
if (t == cfd) {
Expand Down
2 changes: 1 addition & 1 deletion db/db_impl/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ class DBImpl : public DB {
// specified value, this flush request is considered to have completed its
// work of flushing this column family. After completing the work for all
// column families in this request, this flush is considered complete.
typedef std::vector<std::pair<ColumnFamilyData*, uint64_t>> FlushRequest;
using FlushRequest = std::vector<std::pair<ColumnFamilyData*, uint64_t>>;

void GenerateFlushRequest(const autovector<ColumnFamilyData*>& cfds,
FlushRequest* req);
Expand Down
2 changes: 1 addition & 1 deletion db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2812,7 +2812,7 @@ TEST_F(DBTest, GroupCommitTest) {
#endif // TRAVIS

namespace {
typedef std::map<std::string, std::string> KVMap;
using KVMap = std::map<std::string, std::string>;
}

class ModelDB : public DB {
Expand Down
5 changes: 3 additions & 2 deletions db/forward_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class MinIterComparator {
const Comparator* comparator_;
};

typedef std::priority_queue<InternalIterator*, std::vector<InternalIterator*>,
MinIterComparator> MinIterHeap;
using MinIterHeap =
std::priority_queue<InternalIterator*, std::vector<InternalIterator*>,
MinIterComparator>;

/**
* ForwardIterator is a special type of iterator that only supports Seek()
Expand Down
8 changes: 4 additions & 4 deletions db/kv_checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ template <typename T>
class ProtectionInfoKVOTS;

// Aliases for 64-bit protection infos.
typedef ProtectionInfo<uint64_t> ProtectionInfo64;
typedef ProtectionInfoKVOT<uint64_t> ProtectionInfoKVOT64;
typedef ProtectionInfoKVOTC<uint64_t> ProtectionInfoKVOTC64;
typedef ProtectionInfoKVOTS<uint64_t> ProtectionInfoKVOTS64;
using ProtectionInfo64 = ProtectionInfo<uint64_t>;
using ProtectionInfoKVOT64 = ProtectionInfoKVOT<uint64_t>;
using ProtectionInfoKVOTC64 = ProtectionInfoKVOTC<uint64_t>;
using ProtectionInfoKVOTS64 = ProtectionInfoKVOTS<uint64_t>;

template <typename T>
class ProtectionInfo {
Expand Down
4 changes: 2 additions & 2 deletions db/malloc_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace ROCKSDB_NAMESPACE {

#ifdef ROCKSDB_JEMALLOC

typedef struct {
struct MallocStatus {
char* cur;
char* end;
} MallocStatus;
};

static void GetJemallocStatus(void* mstat_arg, const char* status) {
MallocStatus* mstat = reinterpret_cast<MallocStatus*>(mstat_arg);
Expand Down
2 changes: 1 addition & 1 deletion db/pinned_iterators_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PinnedIteratorsManager : public Cleanable {
}
}

typedef void (*ReleaseFunction)(void* arg1);
using ReleaseFunction = void (*)(void* arg1);
void PinPtr(void* ptr, ReleaseFunction release_func) {
assert(pinning_enabled);
if (ptr == nullptr) {
Expand Down
3 changes: 2 additions & 1 deletion env/env_basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#include "test_util/testharness.h"

namespace ROCKSDB_NAMESPACE {
typedef Env* CreateEnvFunc();
namespace {
using CreateEnvFunc = Env*();

// These functions are used to create the various environments under which this
// test can execute. These functions are used to allow the test cases to be
// created without the Env being initialized, thereby eliminating a potential
Expand Down
4 changes: 2 additions & 2 deletions include/rocksdb/advanced_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ struct AdvancedColumnFamilyOptions {
// the tables.
// Default: empty vector -- no user-defined statistics collection will be
// performed.
typedef std::vector<std::shared_ptr<TablePropertiesCollectorFactory>>
TablePropertiesCollectorFactories;
using TablePropertiesCollectorFactories =
std::vector<std::shared_ptr<TablePropertiesCollectorFactory>>;
TablePropertiesCollectorFactories table_properties_collector_factories;

// Maximum number of successive merge operations on a key in the memtable.
Expand Down
3 changes: 0 additions & 3 deletions include/rocksdb/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ class Cache {
// takes in a buffer from the NVM cache and constructs an object using
// it. The callback doesn't have ownership of the buffer and should
// copy the contents into its own buffer.
// typedef std::function<Status(void* buf, size_t size, void** out_obj,
// size_t* charge)>
// CreateCallback;
using CreateCallback = std::function<Status(void* buf, size_t size,
void** out_obj, size_t* charge)>;

Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/cleanable.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Cleanable {
//
// Note that unlike all of the preceding methods, this method is
// not abstract and therefore clients should not override it.
typedef void (*CleanupFunction)(void* arg1, void* arg2);
using CleanupFunction = void (*)(void* arg1, void* arg2);
void RegisterCleanup(CleanupFunction function, void* arg1, void* arg2);
void DelegateCleanupsTo(Cleanable* other);
// DoCleanup and also resets the pointers for reuse
Expand Down
4 changes: 2 additions & 2 deletions include/rocksdb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ struct GetMergeOperandsOptions {
// A collections of table properties objects, where
// key: is the table's file name.
// value: the table properties object of the given table.
typedef std::unordered_map<std::string, std::shared_ptr<const TableProperties>>
TablePropertiesCollection;
using TablePropertiesCollection =
std::unordered_map<std::string, std::shared_ptr<const TableProperties>>;

// A DB is a persistent, versioned ordered map from keys to values.
// A DB is safe for concurrent access from multiple threads without
Expand Down
4 changes: 2 additions & 2 deletions include/rocksdb/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

namespace ROCKSDB_NAMESPACE {

typedef std::unordered_map<std::string, std::shared_ptr<const TableProperties>>
TablePropertiesCollection;
using TablePropertiesCollection =
std::unordered_map<std::string, std::shared_ptr<const TableProperties>>;

class DB;
class ColumnFamilyHandle;
Expand Down
4 changes: 2 additions & 2 deletions include/rocksdb/memtablerep.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class LookupKey;
class SliceTransform;
class Logger;

typedef void* KeyHandle;
using KeyHandle = void*;

extern Slice GetLengthPrefixedSlice(const char* data);

Expand All @@ -61,7 +61,7 @@ class MemTableRep {
// concatenated with values.
class KeyComparator {
public:
typedef ROCKSDB_NAMESPACE::Slice DecodedType;
using DecodedType = ROCKSDB_NAMESPACE::Slice;

virtual DecodedType decode_key(const char* key) const {
// The format of key is frozen and can be treated as a part of the API
Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/persistent_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ROCKSDB_NAMESPACE {
// cache interface is specifically designed for persistent read cache.
class PersistentCache {
public:
typedef std::vector<std::map<std::string, double>> StatsType;
using StatsType = std::vector<std::map<std::string, double>>;

virtual ~PersistentCache() {}

Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/table_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace ROCKSDB_NAMESPACE {
// ++pos) {
// ...
// }
typedef std::map<std::string, std::string> UserCollectedProperties;
using UserCollectedProperties = std::map<std::string, std::string>;

// table properties' human-readable names in the property block.
struct TablePropertiesNames {
Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/transaction_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace ROCKSDB_NAMESPACE {

class LogFile;
typedef std::vector<std::unique_ptr<LogFile>> VectorLogPtr;
using VectorLogPtr = std::vector<std::unique_ptr<LogFile>>;

enum WalFileType {
/* Indicates that WAL file is in archive directory. WAL files are moved from
Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ROCKSDB_NAMESPACE {
using ColumnFamilyId = uint32_t;

// Represents a sequence number in a WAL file.
typedef uint64_t SequenceNumber;
using SequenceNumber = uint64_t;

const SequenceNumber kMinUnCommittedSeq = 1; // 0 is always committed

Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/utilities/backup_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ struct BackupFileInfo {
uint64_t size;
};

typedef uint32_t BackupID;
using BackupID = uint32_t;

struct BackupInfo {
BackupID backup_id = 0U;
Expand Down
2 changes: 1 addition & 1 deletion memory/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Arena : public Allocator {
// Number of bytes allocated in one block
const size_t kBlockSize;
// Array of new[] allocated memory blocks
typedef std::vector<char*> Blocks;
using Blocks = std::vector<char*>;
Blocks blocks_;

struct MmapInfo {
Expand Down
2 changes: 1 addition & 1 deletion memory/memory_usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ROCKSDB_NAMESPACE {
template <class Key, class Value, class Hash>
size_t ApproximateMemoryUsage(
const std::unordered_map<Key, Value, Hash>& umap) {
typedef std::unordered_map<Key, Value, Hash> Map;
using Map = std::unordered_map<Key, Value, Hash>;
return sizeof(umap) +
// Size of all items plus a next pointer for each item.
(sizeof(typename Map::value_type) + sizeof(void*)) * umap.size() +
Expand Down
6 changes: 3 additions & 3 deletions memtable/hash_linklist_rep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
namespace ROCKSDB_NAMESPACE {
namespace {

typedef const char* Key;
typedef SkipList<Key, const MemTableRep::KeyComparator&> MemtableSkipList;
typedef std::atomic<void*> Pointer;
using Key = const char*;
using MemtableSkipList = SkipList<Key, const MemTableRep::KeyComparator&>;
using Pointer = std::atomic<void*>;

// A data structure used as the header of a link list of a hash bucket.
struct BucketHeader {
Expand Down
2 changes: 1 addition & 1 deletion memtable/hash_skiplist_rep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class HashSkipListRep : public MemTableRep {

private:
friend class DynamicIterator;
typedef SkipList<const char*, const MemTableRep::KeyComparator&> Bucket;
using Bucket = SkipList<const char*, const MemTableRep::KeyComparator&>;

size_t bucket_size_;

Expand Down
6 changes: 3 additions & 3 deletions memtable/inlineskiplist_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace ROCKSDB_NAMESPACE {

// Our test skip list stores 8-byte unsigned integers
typedef uint64_t Key;
using Key = uint64_t;

static const char* Encode(const uint64_t* key) {
return reinterpret_cast<const char*>(key);
Expand All @@ -32,7 +32,7 @@ static Key Decode(const char* key) {
}

struct TestComparator {
typedef Key DecodedType;
using DecodedType = Key;

static DecodedType decode_key(const char* b) {
return Decode(b);
Expand All @@ -59,7 +59,7 @@ struct TestComparator {
}
};

typedef InlineSkipList<TestComparator> TestInlineSkipList;
using TestInlineSkipList = InlineSkipList<TestComparator>;

class InlineSkipTest : public testing::Test {
public:
Expand Down
2 changes: 1 addition & 1 deletion memtable/skiplist_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace ROCKSDB_NAMESPACE {

typedef uint64_t Key;
using Key = uint64_t;

struct TestComparator {
int operator()(const Key& a, const Key& b) const {
Expand Down
2 changes: 1 addition & 1 deletion memtable/vectorrep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class VectorRep : public MemTableRep {

private:
friend class Iterator;
typedef std::vector<const char*> Bucket;
using Bucket = std::vector<const char*>;
std::shared_ptr<Bucket> bucket_;
mutable port::RWMutex rwlock_;
bool immutable_;
Expand Down
4 changes: 2 additions & 2 deletions options/cf_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ static std::unordered_map<std::string, OptionTypeInfo>
/* not yet supported
CompressionOptions compression_opts;
TablePropertiesCollectorFactories table_properties_collector_factories;
typedef std::vector<std::shared_ptr<TablePropertiesCollectorFactory>>
TablePropertiesCollectorFactories;
using TablePropertiesCollectorFactories =
std::vector<std::shared_ptr<TablePropertiesCollectorFactory>>;
UpdateStatus (*inplace_callback)(char* existing_value,
uint34_t* existing_value_size,
Slice delta_value,
Expand Down
2 changes: 1 addition & 1 deletion options/options_settable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class OptionsSettableTest : public testing::Test {
};

const char kSpecialChar = 'z';
typedef std::vector<std::pair<size_t, size_t>> OffsetGap;
using OffsetGap = std::vector<std::pair<size_t, size_t>>;

void FillWithSpecialChar(char* start_ptr, size_t total_size,
const OffsetGap& excluded,
Expand Down
2 changes: 1 addition & 1 deletion port/port_example.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CondVar {
// static void Initializer() { ... do something ...; }
// ...
// port::InitOnce(&init_control, &Initializer);
typedef intptr_t OnceType;
using OnceType = intptr_t;
#define LEVELDB_ONCE_INIT 0
extern void InitOnce(port::OnceType*, void (*initializer)());

Expand Down
2 changes: 1 addition & 1 deletion port/port_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static inline void AsmVolatilePause() {
// Returns -1 if not available on this platform
extern int PhysicalCoreID();

typedef pthread_once_t OnceType;
using OnceType = pthread_once_t;
#define LEVELDB_ONCE_INIT PTHREAD_ONCE_INIT
extern void InitOnce(OnceType* once, void (*initializer)());

Expand Down
4 changes: 2 additions & 2 deletions port/sys_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace ROCKSDB_NAMESPACE {
namespace port {

// Avoid including winsock2.h for this definition
typedef struct timeval {
struct timeval {
long tv_sec;
long tv_usec;
} timeval;
};

void gettimeofday(struct timeval* tv, struct timezone* tz);

Expand Down
4 changes: 2 additions & 2 deletions port/win/env_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ static const size_t kSectorSize = 512;

// RAII helpers for HANDLEs
const auto CloseHandleFunc = [](HANDLE h) { ::CloseHandle(h); };
typedef std::unique_ptr<void, decltype(CloseHandleFunc)> UniqueCloseHandlePtr;
using UniqueCloseHandlePtr = std::unique_ptr<void, decltype(CloseHandleFunc)>;

const auto FindCloseFunc = [](HANDLE h) { ::FindClose(h); };
typedef std::unique_ptr<void, decltype(FindCloseFunc)> UniqueFindClosePtr;
using UniqueFindClosePtr = std::unique_ptr<void, decltype(FindCloseFunc)>;

void WinthreadCall(const char* label, std::error_code result) {
if (0 != result.value()) {
Expand Down
2 changes: 1 addition & 1 deletion port/win/env_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class WinClock : public SystemClock {
uint64_t GetPerfCounterFrequency() const { return perf_counter_frequency_; }

private:
typedef VOID(WINAPI* FnGetSystemTimePreciseAsFileTime)(LPFILETIME);
using FnGetSystemTimePreciseAsFileTime = VOID(WINAPI*)(LPFILETIME);

uint64_t perf_counter_frequency_;
uint64_t nano_seconds_per_period_;
Expand Down
4 changes: 2 additions & 2 deletions port/win/port_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#undef DeleteFile

#ifndef _SSIZE_T_DEFINED
typedef SSIZE_T ssize_t;
using ssize_t = SSIZE_T;
#endif

// size_t printf formatting named in the manner of C99 standard formatting
Expand Down Expand Up @@ -292,7 +292,7 @@ static inline void AsmVolatilePause() {
extern int PhysicalCoreID();

// For Thread Local Storage abstraction
typedef DWORD pthread_key_t;
using pthread_key_t = DWORD;

inline int pthread_key_create(pthread_key_t* key, void (*destructor)(void*)) {
// Not used
Expand Down
Loading

0 comments on commit 4750421

Please sign in to comment.