From 316a4740a6b2411d5b0689b9840a45bcc6e69f52 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 5 Jul 2020 23:34:33 +0000 Subject: [PATCH] Move words_bigendian into `if constexpr` `words_bigendian` is `constexpr`, so move the tests on it behind `if constexpr` to encourage the compiler to prune unreachable paths. --- similar/2d/font.cpp | 2 +- similar/main/gameseg.cpp | 2 +- similar/main/multi.cpp | 8 ++++---- similar/main/multibot.cpp | 4 ++-- similar/main/net_udp.cpp | 4 ++-- similar/main/polyobj.cpp | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/similar/2d/font.cpp b/similar/2d/font.cpp index d1c7b595a..6e8c355ef 100644 --- a/similar/2d/font.cpp +++ b/similar/2d/font.cpp @@ -968,7 +968,7 @@ static std::unique_ptr gr_internal_init_font(const char *fontname) const unsigned ft_h = font->ft_h; std::generate_n(ft_chars, nchars, [is_color, ft_h, &w, &ptr]{ const unsigned s = INTEL_SHORT(*w); - if (words_bigendian) + if constexpr (words_bigendian) *w = static_cast(s); ++w; const auto r = ptr; diff --git a/similar/main/gameseg.cpp b/similar/main/gameseg.cpp index ec1d213a3..1e95d4a28 100644 --- a/similar/main/gameseg.cpp +++ b/similar/main/gameseg.cpp @@ -1015,7 +1015,7 @@ void create_shortpos_little(const d_level_shared_segment_state &LevelSharedSegme create_shortpos_native(LevelSharedSegmentState, spp, objp); // swap the short values for the big-endian machines. - if (words_bigendian) + if constexpr (words_bigendian) { spp.xo = INTEL_SHORT(spp.xo); spp.yo = INTEL_SHORT(spp.yo); diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index b76f98079..f0e431bb2 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -2200,7 +2200,7 @@ static void multi_do_controlcen_fire(const ubyte *buf) int count = 1; memcpy(&to_target, buf+count, 12); count += 12; - if (words_bigendian)// swap the vector to_target + if constexpr (words_bigendian)// swap the vector to_target { to_target.x = INTEL_INT(to_target.x); to_target.y = INTEL_INT(to_target.y); @@ -2235,7 +2235,7 @@ static void multi_do_create_powerup(fvmobjptr &vmobjptr, fvmsegptridx &vmsegptri count += 2; objnum_t objnum = GET_INTEL_SHORT(buf + count); count += 2; memcpy(&new_pos, buf+count, sizeof(vms_vector)); count+=sizeof(vms_vector); - if (words_bigendian) + if constexpr (words_bigendian) { new_pos.x = SWAPINT(new_pos.x); new_pos.y = SWAPINT(new_pos.y); @@ -2970,7 +2970,7 @@ void multi_send_controlcen_fire(const vms_vector &to_goal, int best_gun_num, obj count += 1; multi_command multibuf; - if (words_bigendian) + if constexpr (words_bigendian) { vms_vector swapped_vec; swapped_vec.x = INTEL_INT(static_cast(to_goal.x)); @@ -3010,7 +3010,7 @@ void multi_send_create_powerup(const powerup_type_t powerup_type, const vcsegidx multibuf[count] = powerup_type; count += 1; PUT_INTEL_SHORT(&multibuf[count], segnum ); count += 2; PUT_INTEL_SHORT(&multibuf[count], objnum ); count += 2; - if (words_bigendian) + if constexpr (words_bigendian) { vms_vector swapped_vec; swapped_vec.x = INTEL_INT(static_cast(pos.x)); diff --git a/similar/main/multibot.cpp b/similar/main/multibot.cpp index 17bd0fc2a..6575288f5 100644 --- a/similar/main/multibot.cpp +++ b/similar/main/multibot.cpp @@ -526,7 +526,7 @@ void multi_send_robot_fire(const vmobjptridx_t obj, int gun_num, const vms_vecto PUT_INTEL_SHORT(&multibuf[loc], s); loc += 3; multibuf[loc] = gun_num; loc += 1; - if (words_bigendian) + if constexpr (words_bigendian) { vms_vector swapped_vec; swapped_vec.x = INTEL_INT(static_cast(fire.x)); @@ -706,7 +706,7 @@ static void multi_send_create_robot_powerups(const object_base &del_obj) multibuf[loc] = del_obj.contains_type; loc += 1; multibuf[loc] = del_obj.contains_id; loc += 1; PUT_INTEL_SHORT(&multibuf[loc], del_obj.segnum); loc += 2; - if (words_bigendian) + if constexpr (words_bigendian) { vms_vector swapped_vec; swapped_vec.x = INTEL_INT(static_cast(del_obj.pos.x)); diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index 7da5a85ed..abceaf94c 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -2027,7 +2027,7 @@ void net_udp_send_objects(void) PUT_INTEL_INT(&object_buffer[loc], remote_objnum); loc += 4; // use object_rw to send objects for now. if object sometime contains some day contains something useful the client should know about, we should use it. but by now it's also easier to use object_rw because then we also do not need fix64 timer values. multi_object_to_object_rw(vmobjptr(i), reinterpret_cast(&object_buffer[loc])); - if (words_bigendian) + if constexpr (words_bigendian) object_rw_swap(reinterpret_cast(&object_buffer[loc]), 1); loc += sizeof(object_rw); } @@ -2175,7 +2175,7 @@ static void net_udp_read_object_packet( ubyte *data ) Assert(obj->segnum == segment_none); } Assert(objnum < MAX_OBJECTS); - if (words_bigendian) + if constexpr (words_bigendian) object_rw_swap(reinterpret_cast(&data[loc]), 1); multi_object_rw_to_object(reinterpret_cast(&data[loc]), obj); loc += sizeof(object_rw); diff --git a/similar/main/polyobj.cpp b/similar/main/polyobj.cpp index e068ebafc..dcbc0edb1 100644 --- a/similar/main/polyobj.cpp +++ b/similar/main/polyobj.cpp @@ -417,8 +417,8 @@ static polymodel *read_model_file(polymodel *pm,const char *filename,robot_info #if DXX_WORDS_NEED_ALIGNMENT align_polygon_model_data(pm); #endif - if (words_bigendian) - swap_polygon_model_data(pm->model_data.get()); + if constexpr (words_bigendian) + swap_polygon_model_data(pm->model_data.get()); return pm; } @@ -763,8 +763,8 @@ void polygon_model_data_read(polymodel *pm, PHYSFS_File *fp) #if DXX_WORDS_NEED_ALIGNMENT align_polygon_model_data(pm); #endif - if (words_bigendian) - swap_polygon_model_data(pm->model_data.get()); + if constexpr (words_bigendian) + swap_polygon_model_data(pm->model_data.get()); #if defined(DXX_BUILD_DESCENT_I) g3_validate_polygon_model(pm->model_data.get(), model_data_size); #elif defined(DXX_BUILD_DESCENT_II)