util/LazyRandomEngine: use std::optional to avoid allocation

Signed-off-by: Shen-Ta Hsieh <ibmibmibm.tw@gmail.com>
This commit is contained in:
Shen-Ta Hsieh
2021-11-14 03:53:42 +08:00
parent a8c77a6fba
commit e783c2bd2c
2 changed files with 9 additions and 17 deletions

View File

@@ -19,12 +19,10 @@
#include "LazyRandomEngine.hxx"
void
LazyRandomEngine::AutoCreate()
{
if (engine != nullptr)
void LazyRandomEngine::AutoCreate() {
if (engine)
return;
std::random_device rd;
engine = new std::mt19937(rd());
engine.emplace(rd());
}