Skip to content

Commit

Permalink
Fix array size checking on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sverch committed Jan 17, 2014
1 parent aa020ca commit b5365b0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,12 @@ namespace {
"zz"
};

// Helper template to get the number of elements in the fieldNames array in a cross platform way
template <typename T, size_t N>
size_t countof( T (&array)[N] )
{
return N;
};
}

/*
Expand All @@ -1253,7 +1259,7 @@ namespace {
// NOTE: This will be slow, but this part of the test is not timed, so that's ok
BSONObjBuilder b;
b.append("key", i);
for (int j=0; j < sizeof(fieldNames) / sizeof(char*); j++){
for (int j=0; j < countof(fieldNames); j++){
b.append(fieldNames[j], 1);
}
insert(-1, b.obj());
Expand Down Expand Up @@ -1285,7 +1291,7 @@ namespace {
// NOTE: This will be slow, but this part of the test is not timed, so that's ok
BSONObjBuilder b;
b.append("key", i);
for (int j=0; j < sizeof(fieldNames) / sizeof(char*); j++){
for (int j=0; j < countof(fieldNames); j++){
b.append(fieldNames[j], 1);
}
insert(-1, b.obj());
Expand All @@ -1312,7 +1318,7 @@ namespace {
// NOTE: This will be slow, but this part of the test is not timed, so that's ok
BSONObjBuilder b;
b.append("key", i);
for (int j=0; j < sizeof(fieldNames) / sizeof(char*); j++){
for (int j=0; j < countof(fieldNames); j++){
b.append(fieldNames[j], 1);
}
insert(-1, b.obj());
Expand Down Expand Up @@ -1343,7 +1349,7 @@ namespace {
// NOTE: This will be slow, but this part of the test is not timed, so that's ok
BSONObjBuilder b;
b.append("key", i);
for (int j=0; j < sizeof(fieldNames) / sizeof(char*); j++){
for (int j=0; j < countof(fieldNames); j++){
b.append(fieldNames[j], 1);
}
insert(-1, b.obj());
Expand Down

0 comments on commit b5365b0

Please sign in to comment.