Skip to content

Commit 12bae35

Browse files
committed
feat(wire): better callback performance
1 parent a12f4bc commit 12bae35

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

cores/esp32/HardwareI2C.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ class HardwareI2C : public Stream {
3838
virtual size_t requestFrom(uint8_t address, size_t len) = 0;
3939

4040
// Update base class to use std::function
41-
virtual void onReceive(std::function<void(int)>) = 0;
42-
virtual void onRequest(std::function<void()>) = 0;
41+
virtual void onReceive(const std::function<void(int)>&) = 0;
42+
virtual void onRequest(const std::function<void()>&) = 0;
4343
};

libraries/Wire/src/Wire.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,14 @@ void TwoWire::flush() {
596596
//i2cFlush(num); // cleanup
597597
}
598598

599-
void TwoWire::onReceive(std::function<void(int)> function) {
599+
void TwoWire::onReceive(const std::function<void(int)>& function) {
600600
#if SOC_I2C_SUPPORT_SLAVE
601601
user_onReceive = function;
602602
#endif
603603
}
604604

605605
// sets function called on slave read
606-
void TwoWire::onRequest(std::function<void()> function) {
606+
void TwoWire::onRequest(const std::function<void()>& function) {
607607
#if SOC_I2C_SUPPORT_SLAVE
608608
user_onRequest = function;
609609
#endif

libraries/Wire/src/Wire.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ class TwoWire : public HardwareI2C {
112112
size_t requestFrom(uint8_t address, size_t len, bool stopBit) override;
113113
size_t requestFrom(uint8_t address, size_t len) override;
114114

115-
void onReceive(std::function<void(int)>) override;
116-
void onRequest(std::function<void()>) override;
115+
void onReceive(const std::function<void(int)>&) override;
116+
void onRequest(const std::function<void()>&) override;
117117

118118
//call setPins() first, so that begin() can be called without arguments from libraries
119119
bool setPins(int sda, int scl);

0 commit comments

Comments
 (0)