MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / addFast

Method addFast

libraries/Adler/Adler32.cpp:72–94  ·  view source on GitHub ↗

Optimized version S1 grows linear S2 grows quadratic only do modulo when S2 reaches halfway uint32_t and at the end of the loop. returns current Adler value

Source from the content-addressed store, hash-verified

70// and at the end of the loop.
71// returns current Adler value
72uint32_t Adler32::addFast(uint8_t * array, uint16_t length)
73{
74 _count += length;
75 uint32_t s1 = _s1;
76 uint32_t s2 = _s2;
77 for (uint16_t i = 0; i < length;)
78 {
79 // if S2 is halfway it is time to do modulo
80 while ((i < length) && (s2 < 2147483648ULL))
81 {
82 s1 += array[i++];
83 s2 += s1;
84 }
85 if (s2 >= ADLER32_MOD_PRIME)
86 {
87 s2 %= ADLER32_MOD_PRIME;
88 if (s1 >= ADLER32_MOD_PRIME) s1 %= ADLER32_MOD_PRIME;
89 }
90 }
91 _s1 = s1;
92 _s2 = s2;
93 return (s2 << 16) | s1;
94}
95
96
97uint32_t Adler32::getAdler()

Callers 2

unittestFunction · 0.45
unittestFunction · 0.45

Calls

no outgoing calls

Tested by 2

unittestFunction · 0.36
unittestFunction · 0.36