HTTP/2: used bitwise operation to replace division and modulo.
Ruslan Ermilov
ru at nginx.com
Mon Mar 5 08:28:29 UTC 2018
On Sun, Mar 04, 2018 at 10:36:43PM -0800, tokers wrote:
> # HG changeset patch
> # User Alex Zhang <zchao1995 at gmail.com>
> # Date 1520229178 -28800
> # Mon Mar 05 13:52:58 2018 +0800
> # Node ID 03ecef37a93d541e55802393636c101a4da14550
> # Parent 265c29b0b8b8c54b1c623268481ed85324ce3c79
> HTTP/2: used bitwise operation to replace division and modulo.
>
> Signed-off-by: Alex Zhang <zchao1995 at gmail.com>
No, thanks.
- there is no difference in assembler output even with -O0,
with either GCC or Clang, and the author likes it the way
it's written;
- this would require parenthesis around the & operator on
the LHS of ==.
- the patch is incomplete.
Also, please fix your MUA so that it doesn't break patches
by wrapping lines.
> diff -r 265c29b0b8b8 -r 03ecef37a93d src/http/v2/ngx_http_v2.c
> --- a/src/http/v2/ngx_http_v2.c Thu Mar 01 11:42:55 2018 +0300
> +++ b/src/http/v2/ngx_http_v2.c Mon Mar 05 13:52:58 2018 +0800
> @@ -1094,7 +1094,7 @@
> "depends on %ui excl:%ui weight:%ui",
> h2c->state.sid, depend, excl, weight);
>
> - if (h2c->state.sid % 2 == 0 || h2c->state.sid <= h2c->last_sid) {
> + if (h2c->state.sid & 0x1 == 0 || h2c->state.sid <= h2c->last_sid) {
> ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
> "client sent HEADERS frame with incorrect identifier
> "
> "%ui, the last was %ui", h2c->state.sid,
> h2c->last_sid);
> diff -r 265c29b0b8b8 -r 03ecef37a93d src/http/v2/ngx_http_v2_filter_module.c
> --- a/src/http/v2/ngx_http_v2_filter_module.c Thu Mar 01 11:42:55 2018
> +0300
> +++ b/src/http/v2/ngx_http_v2_filter_module.c Mon Mar 05 13:52:58 2018
> +0800
> @@ -1149,8 +1149,8 @@
> value -= prefix;
>
> while (value >= 128) {
> - *pos++ = value % 128 + 128;
> - value /= 128;
> + *pos++ = (value & 0x7f) + 128;
> + value >>= 7;
> }
>
> *pos++ = (u_char) value;
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
--
Ruslan Ermilov
Assume stupidity not malice
More information about the nginx-devel
mailing list