public void ApplyBitAndTo(UnmanagedSliceBuilder value) { uint size = checked ((uint)this.Value.Count); // if the value is empty, then 0 AND * will always be zero if (value.Count == 0) { value.Resize(size, 0); return; } // truncate the value if larger, or pad it with zeroes if shorter value.Resize(size, 0); if (size > 0) { unsafe { fixed(byte *ptr = this.Value.Array) { byte *left = value.Data; byte *right = ptr + this.Value.Offset; //TODO: find a way to optimize this for common sizes like 4 or 8 bytes! while (size-- > 0) { *left++ &= *right++; } } } } }
public void ApplyAddTo(UnmanagedSliceBuilder value) { uint size = checked ((uint)this.Value.Count); // if the value is empty, then this is the same thing as adding to 0 if (value.Count == 0) { value.Append(this.Value); return; } // truncate the value if larger, or pad it with zeroes if shorter value.Resize(size, 0); if (size > 0) { unsafe { fixed(byte *ptr = this.Value.Array) { byte *left = value.Data; byte *right = ptr + this.Value.Offset; //TODO: find a way to optimize this for common sizes like 4 or 8 bytes! int carry = 0; while (size-- > 0) { carry += *left + *right++; *left++ = (byte)carry; carry >>= 8; } } } } }