diff options
| author | 2019-10-17 20:07:57 -0400 | |
|---|---|---|
| committer | 2019-10-17 20:29:00 -0400 | |
| commit | a2eccbf075ea686cb54d7ebce719cf9ad6cf551b (patch) | |
| tree | 05b265fb0f7514e405fbe402fccea4fd2127986e /src | |
| parent | video_core/shader/ast: Make Indent() private (diff) | |
| download | yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.tar.gz yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.tar.xz yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.zip | |
video_core/shader/ast: Make Indent() return a string_view
The returned string is simply a substring of our constexpr tabs
string_view, so we can just use a string_view here as well, since the
original string_view is guaranteed to always exist.
Now the function is fully non-allocating.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/shader/ast.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/video_core/shader/ast.cpp b/src/video_core/shader/ast.cpp index f409706cc..9ef1d0a78 100644 --- a/src/video_core/shader/ast.cpp +++ b/src/video_core/shader/ast.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <string> | 5 | #include <string> |
| 6 | #include <string_view> | ||
| 6 | 7 | ||
| 7 | #include <fmt/format.h> | 8 | #include <fmt/format.h> |
| 8 | 9 | ||
| @@ -263,7 +264,9 @@ public: | |||
| 263 | } | 264 | } |
| 264 | 265 | ||
| 265 | void operator()(const ASTIfElse& ast) { | 266 | void operator()(const ASTIfElse& ast) { |
| 266 | inner += Indent() + "else {\n"; | 267 | inner += Indent(); |
| 268 | inner += "else {\n"; | ||
| 269 | |||
| 267 | scope++; | 270 | scope++; |
| 268 | ASTNode current = ast.nodes.GetFirst(); | 271 | ASTNode current = ast.nodes.GetFirst(); |
| 269 | while (current) { | 272 | while (current) { |
| @@ -271,15 +274,18 @@ public: | |||
| 271 | current = current->GetNext(); | 274 | current = current->GetNext(); |
| 272 | } | 275 | } |
| 273 | scope--; | 276 | scope--; |
| 274 | inner += Indent() + "}\n"; | 277 | |
| 278 | inner += Indent(); | ||
| 279 | inner += "}\n"; | ||
| 275 | } | 280 | } |
| 276 | 281 | ||
| 277 | void operator()(const ASTBlockEncoded& ast) { | 282 | void operator()(const ASTBlockEncoded& ast) { |
| 278 | inner += fmt::format("{}Block({}, {});\n", Indent(), ast.start, ast.end); | 283 | inner += fmt::format("{}Block({}, {});\n", Indent(), ast.start, ast.end); |
| 279 | } | 284 | } |
| 280 | 285 | ||
| 281 | void operator()(const ASTBlockDecoded& ast) { | 286 | void operator()([[maybe_unused]] const ASTBlockDecoded& ast) { |
| 282 | inner += Indent() + "Block;\n"; | 287 | inner += Indent(); |
| 288 | inner += "Block;\n"; | ||
| 283 | } | 289 | } |
| 284 | 290 | ||
| 285 | void operator()(const ASTVarSet& ast) { | 291 | void operator()(const ASTVarSet& ast) { |
| @@ -335,22 +341,26 @@ public: | |||
| 335 | } | 341 | } |
| 336 | 342 | ||
| 337 | private: | 343 | private: |
| 338 | std::string& Indent() { | 344 | std::string_view Indent() { |
| 339 | if (memo_scope == scope) { | 345 | if (space_segment_scope == scope) { |
| 340 | return tabs_memo; | 346 | return space_segment; |
| 341 | } | 347 | } |
| 342 | tabs_memo = tabs.substr(0, scope * 2); | 348 | |
| 343 | memo_scope = scope; | 349 | // Ensure that we don't exceed our view. |
| 344 | return tabs_memo; | 350 | ASSERT(scope * 2 < spaces.size()); |
| 351 | |||
| 352 | space_segment = spaces.substr(0, scope * 2); | ||
| 353 | space_segment_scope = scope; | ||
| 354 | return space_segment; | ||
| 345 | } | 355 | } |
| 346 | 356 | ||
| 347 | std::string inner{}; | 357 | std::string inner{}; |
| 348 | u32 scope{}; | 358 | std::string_view space_segment; |
| 349 | 359 | ||
| 350 | std::string tabs_memo{}; | 360 | u32 scope{}; |
| 351 | u32 memo_scope{}; | 361 | u32 space_segment_scope{}; |
| 352 | 362 | ||
| 353 | static constexpr std::string_view tabs{" "}; | 363 | static constexpr std::string_view spaces{" "}; |
| 354 | }; | 364 | }; |
| 355 | 365 | ||
| 356 | std::string ASTManager::Print() { | 366 | std::string ASTManager::Print() { |