Skip to content

Commit bdd2a1d

Browse files
committed
Refactoring
1 parent e0d7582 commit bdd2a1d

9 files changed

Lines changed: 18 additions & 18 deletions

File tree

include/momo/Array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ class ArraySettings
173173
if (capacity <= 2)
174174
newCapacity = 4;
175175
else if (capacity <= 64)
176-
newCapacity = capacity * 2;
176+
newCapacity = 2 * capacity;
177177
else if (linear || capacity < 150)
178178
newCapacity = capacity + 64;
179179
else
180-
newCapacity = capacity + (capacity / 50) * 23; // k^4 < 1 + k + k^2
180+
newCapacity = capacity + 23 * (capacity / 50); // k^4 < 1 + k + k^2
181181
if (newCapacity < minNewCapacity)
182182
newCapacity = minNewCapacity;
183183
return newCapacity;

include/momo/DataColumn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ class DataColumnList
811811
Edge* nextEdge;
812812
};
813813

814-
static const size_t maxEdgeCount = 2 * maxColumnCount;
814+
static const size_t maxEdgeCount = maxColumnCount * 2;
815815

816816
public:
817817
explicit Graph() noexcept
@@ -1179,7 +1179,7 @@ class DataColumnList
11791179
{
11801180
if (!graph.HasEdge(v) || addends[v] != 0)
11811181
continue;
1182-
addends[v] = size_t{1} << (8 * sizeof(size_t) - 1);
1182+
addends[v] = size_t{1} << (sizeof(size_t) * 8 - 1);
11831183
if (!graph.FillAddends(addends.data(), v))
11841184
return false;
11851185
}

include/momo/HashSorter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class HashSorter
393393
const IterThreeComparer& iterThreeComp)
394394
{
395395
size_t leftIndex = 0;
396-
for (size_t i = 0; i < count; i = i * 2 + 2)
396+
for (size_t i = 0; i < count; i = 2 * i + 2)
397397
{
398398
int cmp = iterThreeComp(SMath::Next(begin, i));
399399
if (cmp > 0)
@@ -438,7 +438,7 @@ class HashSorter
438438
static size_t pvMultShift(HashCode value1, size_t value2) noexcept
439439
{
440440
MOMO_STATIC_ASSERT(sizeof(HashCode) >= sizeof(size_t));
441-
static const size_t halfSize = 4 * sizeof(HashCode);
441+
static const size_t halfSize = sizeof(HashCode) * 4;
442442
static const HashCode halfMask = (HashCode{1} << halfSize) - 1;
443443
HashCode res = (value1 >> halfSize) * (value2 >> halfSize)
444444
+ (((value1 >> halfSize) * (value2 & halfMask)) >> halfSize)

include/momo/MemPool.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ class MemPool : private TParams
799799
{
800800
size_t blockIndex = Params::blockCount;
801801
blockIndex -= static_cast<size_t>(-pvGetFirstBlockIndex(chunk)); // gcc
802-
return chunk + Params::blockAlignment + Params::blockSize * blockIndex;
802+
return chunk + Params::blockAlignment + blockIndex * Params::blockSize;
803803
}
804804

805805
bool pvIsChunkBytesNear() const noexcept
@@ -935,7 +935,7 @@ namespace internal
935935
{
936936
uint32_t nextBlock = (i + 1 < blockCount)
937937
? static_cast<uint32_t>(chunkCount * blockCount + i + 1) : nullPtr;
938-
pvSetNextBlock(nextBlock, chunk + mBlockSize * i);
938+
pvSetNextBlock(nextBlock, chunk + i * mBlockSize);
939939
}
940940
mBlockHead = static_cast<uint32_t>(chunkCount * blockCount);
941941
mChunks.AddBackNogrow(chunk);

include/momo/ObjectManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class ObjectRelocator
111111
Object* srcObjects, Object* dstObjects, size_t count) noexcept
112112
{
113113
if (count > 0)
114-
internal::MemCopyer::CopyBuffer(srcObjects, dstObjects, sizeof(Object) * count);
114+
internal::MemCopyer::CopyBuffer(srcObjects, dstObjects, count * sizeof(Object));
115115
}
116116

117117
private:
@@ -233,7 +233,7 @@ namespace internal
233233
}
234234

235235
private:
236-
MOMO_ALIGNED_STORAGE(sizeof(Object) * count, alignment) mBuffer;
236+
MOMO_ALIGNED_STORAGE(count * sizeof(Object), alignment) mBuffer;
237237
};
238238

239239
template<typename TObject, typename TMemManager, typename... ObjectArgs>

include/momo/RadixSorter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace internal
7474
{
7575
typedef decltype(codeGetter(begin)) Code;
7676
pvSort<Code>(begin, count, codeGetter, iterSwapper, itemsGrouper,
77-
8 * sizeof(Code) - radixSize);
77+
sizeof(Code) * 8 - radixSize);
7878
}
7979

8080
private:

include/momo/SegmentedArray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class SegmentedArraySettings<SegmentedArrayItemCountFunc::sqrt, tLogInitialItemC
126126

127127
static size_t pvSegIndexToLogItemCount(size_t segIndex) noexcept
128128
{
129-
return internal::UIntMath<>::Log2((segIndex * 2 + 4) / 3);
129+
return internal::UIntMath<>::Log2((2 * segIndex + 4) / 3);
130130
}
131131
};
132132

include/momo/details/ArrayBucket.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ namespace internal
296296
{
297297
ArrayMemPool& arrayMemPool = params.GetArrayMemPool();
298298
ArrayMemory memory(arrayMemPool);
299-
Array array = Array::CreateCap(maxFastCount * 2,
299+
Array array = Array::CreateCap(2 * maxFastCount,
300300
MemManagerPtr(arrayMemPool.GetMemManager()));
301301
Item* newItems = array.GetItems();
302302
ItemTraits::RelocateCreate(params.GetMemManager(), items, newItems,
@@ -337,7 +337,7 @@ namespace internal
337337
Array& array = pvGetArray();
338338
array.RemoveBack();
339339
if (2 < count && count <= array.GetCapacity() / 4)
340-
array.TryShrink(count * 2);
340+
array.TryShrink(2 * count);
341341
}
342342
}
343343

include/momo/details/TreeNode.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace internal
7070

7171
typedef internal::MemManagerPtr<MemManager> MemManagerPtr;
7272

73-
static const size_t internalOffset = UIntMath<>::Ceil(sizeof(Node*) * (maxCapacity + 1),
73+
static const size_t internalOffset = UIntMath<>::Ceil((maxCapacity + 1) * sizeof(Node*),
7474
UIntConst::maxAlignment);
7575

7676
static const size_t leafMemPoolCount = maxCapacity / (2 * capacityStep) + 1;
@@ -81,7 +81,7 @@ namespace internal
8181
private:
8282
static const size_t itemOffset = UIntMath<>::Ceil(sizeof(Node), ItemTraits::alignment);
8383
static const size_t internalNodeSize =
84-
internalOffset + itemOffset + sizeof(Item) * maxCapacity;
84+
internalOffset + itemOffset + maxCapacity * sizeof(Item);
8585

8686
typedef MemPoolParamsStatic<internalNodeSize, UIntConst::maxAlignment,
8787
MemPoolParams::blockCount, MemPoolParams::cachedFreeBlockCount> InternalMemPoolParams;
@@ -100,7 +100,7 @@ namespace internal
100100
for (size_t i = 0; i < leafMemPoolCount; ++i)
101101
{
102102
size_t capacity = maxCapacity - i * capacityStep;
103-
size_t leafNodeSize = itemOffset + sizeof(Item) * capacity;
103+
size_t leafNodeSize = itemOffset + capacity * sizeof(Item);
104104
mLeafMemPools.AddBackNogrow(LeafMemPool(MemPoolParams(leafNodeSize),
105105
MemManagerPtr(memManager)));
106106
}
@@ -190,7 +190,7 @@ namespace internal
190190
{
191191
size_t capacity = maxCapacity;
192192
if (IsLeaf())
193-
capacity -= capacityStep * size_t{mMemPoolIndex};
193+
capacity -= size_t{mMemPoolIndex} * capacityStep;
194194
return capacity;
195195
}
196196

0 commit comments

Comments
 (0)