diff options
author | 2017-04-05 08:11:44 -0700 | |
---|---|---|
committer | 2017-04-05 08:11:44 -0700 | |
commit | dd2f706b8b9672f31ee40f678afea54c7bab899d (patch) | |
tree | eec7304e72f861706ce2e62eb2065c6fb891891d /tools/codegen/core | |
parent | bcf9d9f4632e54526b34d44b6b9838bf9626c66a (diff) |
Generate slightly more efficient code
Diffstat (limited to 'tools/codegen/core')
-rwxr-xr-x | tools/codegen/core/gen_settings_ids.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/tools/codegen/core/gen_settings_ids.py b/tools/codegen/core/gen_settings_ids.py index 4253396ead..cfc2c5d0a4 100755 --- a/tools/codegen/core/gen_settings_ids.py +++ b/tools/codegen/core/gen_settings_ids.py @@ -118,25 +118,29 @@ print >>C, 'const uint16_t grpc_setting_id_to_wire_id[] = {%s};' % ','.join( '%d' % s for s in p.slots) print >>H print >>H, "bool grpc_wire_id_to_setting_id(uint32_t wire_id, grpc_chttp2_setting_id *out);" +cgargs = { + 'r': ','.join('%d' % (r if r is not None else 0) for r in p.r), + 't': p.t, + 'offset': abs(p.offset), + 'offset_sign': '+' if p.offset > 0 else '-' + } print >>C, """ bool grpc_wire_id_to_setting_id(uint32_t wire_id, grpc_chttp2_setting_id *out) { - static const uint32_t r[] = {%(r)s}; uint32_t i = wire_id %(offset_sign)s %(offset)d; uint32_t x = i %% %(t)d; uint32_t y = i / %(t)d; uint32_t h = x; - if (y < GPR_ARRAY_SIZE(r)) { - uint32_t delta = (uint32_t)r[y]; - h += delta; + switch (y) { +""" % cgargs +for i, r in enumerate(p.r): + if not r: continue + if r < 0: print >>C, 'case %d: h -= %d; break;' % (i, -r) + else: print >>C, 'case %d: h += %d; break;' % (i, r) +print >>C, """ } *out = (grpc_chttp2_setting_id)h; return h < GPR_ARRAY_SIZE(grpc_setting_id_to_wire_id) && grpc_setting_id_to_wire_id[h] == wire_id; -}""" % { - 'r': ','.join('%d' % (r if r is not None else 0) for r in p.r), - 't': p.t, - 'offset': abs(p.offset), - 'offset_sign': '+' if p.offset > 0 else '-' - } +}""" % cgargs print >>H, """ typedef enum { |