@@ -439,29 +439,30 @@ public:
439
439
len = 1 ;
440
440
}
441
441
442
- Counter & operator ++() {
443
- inc_string (max_digits - 1 );
442
+ inline Counter & operator ++() {
443
+ inc_string (buffer + max_digits - 1 );
444
444
++val;
445
445
return *this ;
446
446
}
447
447
448
- operator unsigned int () const { return val; }
449
- const char * c_str () const { return buffer + max_digits - len; }
450
- size_t strlen () const { return len; }
448
+ inline operator unsigned int () const { return val; }
449
+ inline const char * c_str () const { return buffer + max_digits - len; }
450
+ inline size_t strlen () const { return len; }
451
451
452
452
protected:
453
- inline void inc_string (int pos) {
454
- if (pos < 0 )
455
- return ;
456
-
457
- if (buffer[pos] < ' 9' ) {
458
- buffer[pos]++;
453
+ inline void inc_string (char * c) {
454
+ // In theory, the line below should be uncommented to avoid writing outside the buffer. In practice however,
455
+ // with max_digits set to 10 or more, we can fit all possible unsigned 32-bit integers in the buffer. The
456
+ // check is skipped to gain a small extra speed improvement.
457
+ // if (c >= buffer) return;
458
+
459
+ if (*c < ' 9' ) {
460
+ *c += 1 ;
459
461
} else {
460
- buffer[pos] = ' 0' ;
461
- inc_string (pos - 1 );
462
+ *c = ' 0' ;
463
+ inc_string (c - 1 );
464
+ len = max (max_digits - (c - buffer) + 1 , len);
462
465
}
463
-
464
- len = max (max_digits - pos, len);
465
466
}
466
467
467
468
protected:
@@ -796,12 +797,12 @@ void loop() {
796
797
br_sha1_init (&sha1_ctx_base);
797
798
br_sha1_update (&sha1_ctx_base, job.last_block_hash .c_str (), job.last_block_hash .length ());
798
799
799
- float start_time = micros ();
800
+ unsigned long start_time = micros ();
800
801
max_micros_elapsed (start_time, 0 );
801
802
802
803
String result = " " ;
803
804
if (LED_BLINKING) digitalWrite (LED_BUILTIN, LOW);
804
- for (Counter<8 > counter; counter < difficulty; ++counter) {
805
+ for (Counter<10 > counter; counter < difficulty; ++counter) {
805
806
// Difficulty loop
806
807
sha1_ctx = sha1_ctx_base;
807
808
0 commit comments