@@ -171,20 +171,17 @@ int compareString(const __FlashStringHelper* a, const char* b) {
171171 return -strcmp_P (b, (const char *) a);
172172}
173173
174+ // On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
175+ // memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
176+ // optimizing for 4-byte alignment here.
174177int compareString (const __FlashStringHelper* a, const __FlashStringHelper* b) {
175178 const char * aa = reinterpret_cast <const char *>(a);
176179 const char * bb = reinterpret_cast <const char *>(b);
177180
178- // On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
179- // memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
180- // optimizing for 4-byte alignment here.
181181 while (true ) {
182- char ca = pgm_read_byte (aa);
183- char cb = pgm_read_byte (bb);
184- if (ca < cb) return -1 ;
185- if (ca > cb) return 1 ;
186- // we hit this condition only if both strings are the same length,
187- // so no need to check both strings for '\0'
182+ uint8_t ca = pgm_read_byte (aa);
183+ uint8_t cb = pgm_read_byte (bb);
184+ if (ca != cb) return (int ) ca - (int ) cb;
188185 if (ca == ' \0 ' ) return 0 ;
189186 aa++;
190187 bb++;
@@ -225,21 +222,18 @@ int compareStringN(const __FlashStringHelper* a, const char* b, size_t n) {
225222 return -strncmp_P (b, (const char *)a, n);
226223}
227224
225+ // On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
226+ // memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
227+ // optimizing for 4-byte alignment here.
228228int compareStringN (const __FlashStringHelper* a, const __FlashStringHelper* b,
229229 size_t n) {
230230 const char * aa = reinterpret_cast <const char *>(a);
231231 const char * bb = reinterpret_cast <const char *>(b);
232232
233- // On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
234- // memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
235- // optimizing for 4-byte alignment here.
236233 while (n > 0 ) {
237- char ca = pgm_read_byte (aa);
238- char cb = pgm_read_byte (bb);
239- if (ca < cb) return -1 ;
240- if (ca > cb) return 1 ;
241- // we hit this condition only if both strings are the same length,
242- // so no need to check both strings for '\0'
234+ uint8_t ca = pgm_read_byte (aa);
235+ uint8_t cb = pgm_read_byte (bb);
236+ if (ca != cb) return (int ) ca - (int ) cb;
243237 if (ca == ' \0 ' ) return 0 ;
244238 aa++;
245239 bb++;
0 commit comments