From 0b60fd0c8c6b9ff704b25e6730b1de6521b1d918 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 20 Jan 2026 21:49:14 -1000 Subject: [PATCH] [core] Avoid heap allocation in str_equals_case_insensitive with string literals (#13312) --- esphome/core/helpers.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 6c06757d8c..ed5c4911ad 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -572,6 +572,10 @@ template constexpr T convert_little_endian(T val) { bool str_equals_case_insensitive(const std::string &a, const std::string &b); /// Compare StringRefs for equality in case-insensitive manner. bool str_equals_case_insensitive(StringRef a, StringRef b); +/// Compare C strings for equality in case-insensitive manner (no heap allocation). +inline bool str_equals_case_insensitive(const char *a, const char *b) { return strcasecmp(a, b) == 0; } +inline bool str_equals_case_insensitive(const std::string &a, const char *b) { return strcasecmp(a.c_str(), b) == 0; } +inline bool str_equals_case_insensitive(const char *a, const std::string &b) { return strcasecmp(a, b.c_str()) == 0; } /// Check whether a string starts with a value. bool str_startswith(const std::string &str, const std::string &start);