-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save flash on generated struct encoding logic (#29608)
* Save flash on generated struct encoding logic Problem: - Structural repetition in the generated code caused needless jumps to be inlined in very large numbers in `Encode` methods, in ways that could be factored-out. This PR: - Changes the generated code to use a proxy encoder class that reduces expanded inlined code, reduces 64 bit arguments usage and maintains correct early return behavior, while generating significantly smaller method bodies. Testing done: - Unit tests pass - Integration tests pass * Restyled by clang-format * Address review comments * Update src/app/data-model/WrappedStructEncoder.h Co-authored-by: Damian Królik <[email protected]> * Regen --------- Co-authored-by: [email protected] <[email protected]> Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Damian Królik <[email protected]>
- Loading branch information
1 parent
43981ac
commit fc44549
Showing
4 changed files
with
1,786 additions
and
2,072 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app/data-model/Encode.h> | ||
|
||
#include <lib/core/CHIPError.h> | ||
#include <lib/core/DataModelTypes.h> | ||
#include <lib/core/TLV.h> | ||
|
||
#include <utility> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace DataModel { | ||
|
||
class WrappedStructEncoder | ||
{ | ||
public: | ||
WrappedStructEncoder(TLV::TLVWriter & writer, TLV::Tag outerTag) : mWriter(writer) | ||
{ | ||
mLastError = mWriter.StartContainer(outerTag, TLV::kTLVType_Structure, mOuter); | ||
} | ||
|
||
template <typename... Args> | ||
void Encode(uint8_t contextTag, Args &&... args) | ||
{ | ||
VerifyOrReturn(mLastError == CHIP_NO_ERROR); | ||
mLastError = DataModel::Encode(mWriter, TLV::ContextTag(contextTag), std::forward<Args>(args)...); | ||
} | ||
|
||
CHIP_ERROR Finalize() | ||
{ | ||
if (mLastError == CHIP_NO_ERROR) | ||
{ | ||
mLastError = mWriter.EndContainer(mOuter); | ||
} | ||
return mLastError; | ||
} | ||
|
||
private: | ||
TLV::TLVWriter & mWriter; | ||
CHIP_ERROR mLastError = CHIP_NO_ERROR; | ||
TLV::TLVType mOuter; | ||
}; | ||
|
||
} // namespace DataModel | ||
} // namespace app | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.