Skip to content

Commit b40c052

Browse files
author
Kai Liu
committed
Fix all the comparison issue in fb dev servers
1 parent 113a08c commit b40c052

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

util/autovector.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <algorithm>
88
#include <cassert>
9-
#include <exception>
9+
#include <stdexcept>
1010
#include <iterator>
1111
#include <vector>
1212

util/autovector_test.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ TEST(AutoVectorTest, PushBackAndPopBack) {
4848
}
4949

5050
TEST(AutoVectorTest, EmplaceBack) {
51-
typedef std::pair<int, std::string> ValueType;
51+
typedef std::pair<size_t, std::string> ValueType;
5252
autovector<ValueType, kSize> vec;
5353

5454
for (size_t i = 0; i < 1000 * kSize; ++i) {
@@ -143,18 +143,19 @@ TEST(AutoVectorTest, Iterators) {
143143
// HACK: make sure -> works
144144
ASSERT_TRUE(!old->empty());
145145
ASSERT_EQ(old_val, *old);
146-
ASSERT_TRUE(old_val != *pos);
146+
ASSERT_TRUE(pos == vec.end() || old_val != *pos);
147147
}
148148

149149
pos = vec.begin();
150-
typedef autovector<std::string>::difference_type diff_type;
151-
for (diff_type i = 0; i < vec.size(); i += 2) {
150+
for (size_t i = 0; i < vec.size(); i += 2) {
152151
// Cannot use ASSERT_EQ since that macro depends on iostream serialization
153152
ASSERT_TRUE(pos + 2 - 2 == pos);
154153
pos += 2;
155-
ASSERT_TRUE(i + 2 == pos - vec.begin());
156154
ASSERT_TRUE(pos >= vec.begin());
157155
ASSERT_TRUE(pos <= vec.end());
156+
157+
size_t diff = static_cast<size_t>(pos - vec.begin());
158+
ASSERT_EQ(i + 2, diff);
158159
}
159160
}
160161

@@ -191,7 +192,7 @@ void BenchmarkVectorCreationAndInsertion(
191192
}
192193

193194
template <class TVector>
194-
void BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) {
195+
size_t BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) {
195196
TVector v;
196197
for (const auto& item : GetTestKeys(elem_size)) {
197198
v.push_back(item);
@@ -211,6 +212,8 @@ void BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) {
211212
cout << "performed " << ops << " sequence access against " << name << "\n\t"
212213
<< "size: " << elem_size << "\n\t"
213214
<< "total time elapsed: " << elapsed << " (ns)" << endl;
215+
// HACK avoid compiler's optimization to ignore total
216+
return total;
214217
}
215218

216219
// This test case only reports the performance between std::vector<string>

0 commit comments

Comments
 (0)