mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
5f75647224
Summary: yfeldblum were talking about whether this code might make sense in folly. That led to polishing it a bit more. The hot path is only six instructions now. It's not any faster in a tight generateUniqueID loop but uses only one thread_local slot and a bit less global storage. Reviewed By: strager Differential Revision: D12927275 fbshipit-source-id: 94a5872c61dfe9dd441f1f34fab65f93c12997d8
38 lines
917 B
C++
38 lines
917 B
C++
/*
|
|
* Copyright (c) 2018-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
|
|
#include "eden/fs/utils/IDGen.h"
|
|
#include <gtest/gtest.h>
|
|
|
|
using namespace facebook::eden;
|
|
|
|
TEST(IDGenTest, initialIDIsNonZero) {
|
|
EXPECT_NE(0, generateUniqueID());
|
|
}
|
|
|
|
TEST(IDGenTest, producesUniqueIDs) {
|
|
auto id1 = generateUniqueID();
|
|
auto id2 = generateUniqueID();
|
|
auto id3 = generateUniqueID();
|
|
EXPECT_NE(0, id1);
|
|
EXPECT_NE(id1, id2);
|
|
EXPECT_NE(id2, id3);
|
|
EXPECT_NE(id2, id3);
|
|
}
|
|
|
|
TEST(IDGenTest, monotonic) {
|
|
auto previous = generateUniqueID();
|
|
for (int i = 0; i < 100000; ++i) {
|
|
auto next = generateUniqueID();
|
|
EXPECT_EQ(previous + 1, next);
|
|
previous = next;
|
|
}
|
|
}
|