[all-commits] [llvm/llvm-project] d65751: [lldb] Improve maintainability and readability for...
Pete Lawrence via All-commits
all-commits at lists.llvm.org
Tue Jan 23 16:08:05 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: d657519838e4b2310e13ec5ff52599e041860825
https://github.com/llvm/llvm-project/commit/d657519838e4b2310e13ec5ff52599e041860825
Author: Pete Lawrence <plawrence at apple.com>
Date: 2024-01-23 (Tue, 23 Jan 2024)
Changed paths:
M lldb/source/Core/ValueObject.cpp
Log Message:
-----------
[lldb] Improve maintainability and readability for ValueObject methods (#75865)
As I worked through changes to another PR
(https://github.com/llvm/llvm-project/pull/74912), I couldn't help but
rewrite a few methods for readability, maintainability, and possibly
some behavior correctness too.
1. Exiting early instead of nested `if`-statements, which:
- Reduces indentation levels for all subsequent lines
- Treats missing pre-conditions similar to an error
- Clearly indicates that the full length of the method is the "happy
path".
2. Explicitly return empty Value Object shared pointers for those error
(like) situations, which
- Reduces the time it takes a maintainer to figure out what the method
actually returns based on those conditions.
3. Converting a mix of `if` and `if`-`else`-statements around an enum
into one `switch` statement, which:
- Consolidates the former branching logic
- Lets the compiler warn you of a (future) missing enum case
- This one may actually change behavior slightly, because what was an
early test for one enum case, now happens later on in the `switch`.
4. Consolidating near-identical, "copy-pasta" logic into one place,
which:
- Separates the common code to the diverging paths.
- Highlights the differences between the code paths.
rdar://119833526
More information about the All-commits
mailing list