Skip to content

Commit 4ef1707

Browse files
authored
Remove custom MakeUnique. (#1080)
Since Amber was updated past c++14 we can now use `std::make_unique` instead of the local `amber::MakeUnique`. This Cl updates all uses and removes the custom version.
1 parent 30458a7 commit 4ef1707

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+273
-324
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ cmake-build-*/
3535

3636
### The 'compile_commands' file can be generated at root
3737
compile_commands.json
38+
.DS_Store

android_sample/jni/amber_script.cc

+27-15
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include "amber_script.h"
1616

17-
#include "src/make_unique.h"
18-
1917
namespace amber {
2018
namespace android {
2119
namespace {
@@ -28,33 +26,39 @@ const char kShaderExtension[] = ".spv";
2826
bool IsEndedWith(const std::string& path, const std::string& end) {
2927
const size_t path_size = path.size();
3028
const size_t end_size = end.size();
31-
if (path_size < end_size)
29+
if (path_size < end_size) {
3230
return false;
31+
}
3332

3433
return path.compare(path_size - end_size, end_size, end) == 0;
3534
}
3635

3736
bool IsStartedWith(const std::string& path, const std::string& start) {
3837
const size_t path_size = path.size();
3938
const size_t start_size = start.size();
40-
if (path_size < start_size)
39+
if (path_size < start_size) {
4140
return false;
41+
}
4242

4343
return path.compare(0, start_size, start) == 0;
4444
}
4545

4646
std::string GetShaderID(const std::string& shader_name) {
4747
size_t spv_extension_pos = shader_name.find_last_of('.');
48-
if (spv_extension_pos == std::string::npos)
48+
if (spv_extension_pos == std::string::npos) {
4949
return std::string();
50+
}
5051

5152
size_t shader_id_pos =
5253
shader_name.find_last_of('.', spv_extension_pos - 1UL) + 1UL;
53-
if (shader_id_pos == std::string::npos)
54+
if (shader_id_pos == std::string::npos) {
5455
return std::string();
56+
}
5557

56-
if (shader_id_pos >= spv_extension_pos || shader_name.size() <= shader_id_pos)
58+
if (shader_id_pos >= spv_extension_pos ||
59+
shader_name.size() <= shader_id_pos) {
5760
return std::string();
61+
}
5862

5963
return shader_name.substr(shader_id_pos, spv_extension_pos - shader_id_pos);
6064
}
@@ -67,27 +71,32 @@ AmberScriptLoader::~AmberScriptLoader() = default;
6771

6872
Result AmberScriptLoader::LoadAllScriptsFromAsset() {
6973
auto shader_names = FindAllScriptsAndReturnShaderNames();
70-
if (script_info_.empty())
74+
if (script_info_.empty()) {
7175
return Result("No Amber script found");
76+
}
7277

7378
for (auto& info : script_info_) {
7479
info.script_content = ReadScript(info.asset_name);
75-
if (info.script_content.empty())
80+
if (info.script_content.empty()) {
7681
return Result(info.asset_name + ":\n\tEmpty Amber script");
82+
}
7783
}
7884

7985
for (auto& info : script_info_) {
8086
for (const auto& shader : shader_names) {
81-
if (!IsStartedWith(shader, info.asset_name + kShaderNameSignature))
87+
if (!IsStartedWith(shader, info.asset_name + kShaderNameSignature)) {
8288
continue;
89+
}
8390

8491
auto shader_content = ReadSpvShader(shader);
85-
if (shader_content.empty())
92+
if (shader_content.empty()) {
8693
return Result(shader + ":\n\tEmpty shader");
94+
}
8795

8896
auto id = GetShaderID(shader);
89-
if (id.empty())
97+
if (id.empty()) {
9098
return Result(shader + ":\n\tFail to get shader ID");
99+
}
91100

92101
info.shader_map[id] = shader_content;
93102
}
@@ -110,8 +119,9 @@ AmberScriptLoader::FindAllScriptsAndReturnShaderNames() {
110119
script_info_.back().asset_name = file_name_in_string;
111120
}
112121

113-
if (IsEndedWith(file_name_in_string, kShaderExtension))
122+
if (IsEndedWith(file_name_in_string, kShaderExtension)) {
114123
shaders.push_back(file_name_in_string);
124+
}
115125
}
116126
AAssetDir_close(asset);
117127

@@ -123,8 +133,9 @@ std::vector<uint8_t> AmberScriptLoader::ReadContent(
123133
auto asset_path = kAmberDir + asset_name;
124134
AAsset* asset = AAssetManager_open(app_context_->activity->assetManager,
125135
asset_path.c_str(), AASSET_MODE_BUFFER);
126-
if (!asset)
136+
if (!asset) {
127137
return std::vector<uint8_t>();
138+
}
128139

129140
size_t size_in_bytes = AAsset_getLength(asset);
130141

@@ -145,8 +156,9 @@ std::string AmberScriptLoader::ReadScript(const std::string& script_name) {
145156
std::vector<uint32_t> AmberScriptLoader::ReadSpvShader(
146157
const std::string& shader_name) {
147158
auto content = ReadContent(shader_name);
148-
if (content.size() % sizeof(uint32_t) != 0)
159+
if (content.size() % sizeof(uint32_t) != 0) {
149160
return std::vector<uint32_t>();
161+
}
150162

151163
return std::vector<uint32_t>(
152164
reinterpret_cast<uint32_t*>(content.data()),

android_sample/jni/main.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ void amber_sample_main(android_app* app) {
6666

6767
if (!failures.empty()) {
6868
LOGE("\nSummary of Failures:");
69-
for (const auto& failure : failures)
69+
for (const auto& failure : failures) {
7070
LOGE("%s", failure.c_str());
71+
}
7172
}
7273
LOGE("\nsummary: %u pass, %u fail",
7374
static_cast<uint32_t>(script_info.size() - failures.size()),
@@ -105,7 +106,7 @@ void android_main(struct android_app* app) {
105106
}
106107

107108
if (result >= 0 && source != nullptr) {
108-
source->process(app, source);
109+
source->process(app, source);
109110
}
110111
}
111112
}

samples/amber.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "samples/ppm.h"
3535
#include "samples/timestamp.h"
3636
#include "src/build-versions.h"
37-
#include "src/make_unique.h"
3837

3938
#if AMBER_ENABLE_SPIRV_TOOLS
4039
#include "spirv-tools/libspirv.hpp"
@@ -533,7 +532,7 @@ int main(int argc, const char** argv) {
533532
delegate.SetScriptPath(file.substr(0, file.find_last_of("/\\") + 1));
534533

535534
amber::Amber am(&delegate);
536-
std::unique_ptr<amber::Recipe> recipe = amber::MakeUnique<amber::Recipe>();
535+
std::unique_ptr<amber::Recipe> recipe = std::make_unique<amber::Recipe>();
537536

538537
result = am.Parse(data, recipe.get());
539538
if (!result.IsSuccess()) {

samples/config_helper.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include <string>
2020
#include <vector>
2121

22-
#include "src/make_unique.h"
23-
2422
#if AMBER_ENGINE_DAWN
2523
#include "samples/config_helper_dawn.h"
2624
#endif // AMBER_ENGINE_DAWN
@@ -51,14 +49,14 @@ amber::Result ConfigHelper::CreateConfig(
5149
switch (engine) {
5250
case amber::kEngineTypeVulkan:
5351
#if AMBER_ENGINE_VULKAN
54-
impl_ = amber::MakeUnique<ConfigHelperVulkan>();
52+
impl_ = std::make_unique<ConfigHelperVulkan>();
5553
break;
5654
#else
5755
return amber::Result("Unable to create engine config for Vulkan");
5856
#endif // AMBER_ENGINE_VULKAN
5957
case amber::kEngineTypeDawn:
6058
#if AMBER_ENGINE_DAWN
61-
impl_ = amber::MakeUnique<ConfigHelperDawn>();
59+
impl_ = std::make_unique<ConfigHelperDawn>();
6260
break;
6361
#else
6462
return amber::Result("Unable to create engine config for Dawn");

samples/ppm_test.cc

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

2222
#include "amber/result.h"
2323
#include "gtest/gtest.h"
24-
#include "src/make_unique.h"
2524

2625
namespace amber {
2726
namespace {

src/amber.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "src/descriptor_set_and_binding_parser.h"
2525
#include "src/engine.h"
2626
#include "src/executor.h"
27-
#include "src/make_unique.h"
2827
#include "src/parser.h"
2928
#include "src/vkscript/parser.h"
3029

@@ -96,9 +95,9 @@ amber::Result Amber::Parse(const std::string& input, amber::Recipe* recipe) {
9695

9796
std::unique_ptr<Parser> parser;
9897
if (input.substr(0, 7) == "#!amber") {
99-
parser = MakeUnique<amberscript::Parser>(GetDelegate());
98+
parser = std::make_unique<amberscript::Parser>(GetDelegate());
10099
} else {
101-
parser = MakeUnique<vkscript::Parser>(GetDelegate());
100+
parser = std::make_unique<vkscript::Parser>(GetDelegate());
102101
}
103102

104103
Result r = parser->Parse(input);

0 commit comments

Comments
 (0)