Skip to content

Commit

Permalink
Avoid unnecessary cast to String in API
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinroger committed Feb 5, 2016
1 parent ce61fa2 commit 00c95b8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Homie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void HomieClass::setResetHook(void (*callback)(void)) {
this->_shared_interface.resetHook = callback;
}

bool HomieClass::setNodeProperty(HomieNode& node, String property, String value, bool retained) {
bool HomieClass::setNodeProperty(HomieNode& node, const char* property, const char* value, bool retained) {
if (!this->isReadyToOperate()) {
return false;
}
Expand All @@ -88,7 +88,7 @@ bool HomieClass::setNodeProperty(HomieNode& node, String property, String value,
topic += node.id;
topic += "/";
topic += property;
return this->_shared_interface.mqtt->publish(topic.c_str(), value.c_str(), retained);
return this->_shared_interface.mqtt->publish(topic.c_str(), value, retained);
}

HomieClass Homie;
6 changes: 3 additions & 3 deletions src/Homie.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ namespace HomieInternals {
void setSetupFunction(void (*callback)(void));
void setLoopFunction(void (*callback)(void));
bool isReadyToOperate();
bool setNodeProperty(HomieNode& node, const char* property, const char* value, bool retained = true) {
this->setNodeProperty(node, String(property), String(value), retained);
bool setNodeProperty(HomieNode& node, String property, String value, bool retained = true) {
this->setNodeProperty(node, property.c_str(), value.c_str(), retained);
}
bool setNodeProperty(HomieNode& node, String property, String value, bool retained = true);
bool setNodeProperty(HomieNode& node, const char* property, const char* value, bool retained = true);
private:
Boot* _boot;
SharedInterface _shared_interface;
Expand Down
4 changes: 2 additions & 2 deletions src/Homie/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ void LoggerClass::setLogging(bool enable) {
this->_logging_enabled = enable;
}

void LoggerClass::log(String text) {
void LoggerClass::log(const char* text) {
if (this->_logging_enabled) {
Serial.print(text);
}
}

void LoggerClass::logln(String text) {
void LoggerClass::logln(const char* text) {
if (this->_logging_enabled) {
Serial.println(text);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Homie/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace HomieInternals {
public:
LoggerClass();
void setLogging(bool enable);
void log(const char* text) {
this->log(String(text));
void log(String text) {
this->log(text.c_str());
}
void log(String text);
void logln(const char* text = "") {
this->logln(String(text));
void log(const char* text);
void logln(String text) {
this->logln(text.c_str());
}
void logln(String text);
void logln(const char* text = "");

private:
bool _logging_enabled;
Expand Down

0 comments on commit 00c95b8

Please sign in to comment.