[captive_portal] Use stack buffer for IP address logging in DNS server - #12679
Conversation
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#12679
components: [captive_portal]
refresh: 1h(Added by the PR bot) |
|
👋 Hi there! This PR modifies 1 file(s) with codeowners. @esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
There was a problem hiding this comment.
Pull request overview
This PR eliminates heap allocation during DNS server startup logging by replacing ip.str().c_str() (which creates a temporary std::string) with a stack-allocated buffer and the str_to() method. The change is guarded with a preprocessor directive to prevent unused variable warnings when verbose logging is disabled.
- Replaces heap allocation with stack buffer for IP address logging in DNS server
- Guards the buffer and log statement with
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE - Uses the existing
network::IP_ADDRESS_BUFFER_SIZEconstant (40 bytes) andstr_to()method
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #12679 +/- ##
==========================================
- Coverage 73.36% 73.34% -0.03%
==========================================
Files 53 53
Lines 11283 11283
Branches 1532 1532
==========================================
- Hits 8278 8275 -3
- Misses 2605 2607 +2
- Partials 400 401 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Memory Impact AnalysisComponents:
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
|
Thanks |
What does this implement/fix?
Eliminates heap allocation during DNS server startup logging by using a stack buffer with
str_to()instead ofip.str().c_str()which creates a temporarystd::string.The buffer and log statement are guarded with
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSEto avoid unused variable warnings when verbose logging is disabled.This one doesn't matter so much but its in a place where someone might copy this pattern so good to fix since I noticed it.
Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:captive_portal:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: