Skip to content

Commit 19376c8

Browse files
jerome-pouillerJuha Heiskanen
authored andcommitted
Simplify array indexes
Sometime, the code of the nanostack use "0 + i" to address arrays. This syntax seems pointless. So, simplify it.
1 parent c808661 commit 19376c8

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ static uint8_t ws_generate_exluded_channel_list_from_active_channels(ws_excluded
553553
memset(excluded_data, 0, sizeof(ws_excluded_channel_data_t));
554554

555555
for (uint8_t i = 0; i < number_of_channels; i++) {
556-
if (!(global_channel_mask[0 + (i / 32)] & (1U << (i % 32)))) {
556+
if (!(global_channel_mask[i / 32] & (1U << (i % 32)))) {
557557
//Global exluded channel
558558
if (active_range) {
559559
//Mark range stop here
@@ -562,15 +562,15 @@ static uint8_t ws_generate_exluded_channel_list_from_active_channels(ws_excluded
562562
continue;
563563
}
564564

565-
if (selected_channel_mask[0 + (i / 32)] & (1U << (i % 32))) {
565+
if (selected_channel_mask[i / 32] & (1U << (i % 32))) {
566566
if (active_range) {
567567
//Mark range stop here
568568
active_range = false;
569569
}
570570
} else {
571571
//Mark excluded channel
572572
//Swap Order already here
573-
excluded_data->channel_mask[ 0 + (i / 32)] |= 1U << (31 - (i % 32));
573+
excluded_data->channel_mask[i / 32] |= 1U << (31 - (i % 32));
574574
excluded_data->excluded_channel_count++;
575575

576576
if (excluded_data->excluded_range_length < WS_EXCLUDED_MAX_RANGE_TO_SEND) {
@@ -1359,7 +1359,7 @@ static void ws_bootstrap_decode_exclude_range_to_mask_by_range(void *mask_buffer
13591359
}
13601360
if (channel >= range_start && channel <= range_stop) {
13611361
//mask_ptr[mask_index] |= 1U << (31 - channel_index);
1362-
mask_ptr[0 + (channel / 32)] |= 1U << (31 - (channel % 32));
1362+
mask_ptr[channel / 32] |= 1U << (31 - (channel % 32));
13631363
} else if (channel > range_stop) {
13641364
break;
13651365
}
@@ -3506,7 +3506,7 @@ static void ws_set_asynch_channel_list(protocol_interface_info_entry_t *cur, asy
35063506
if (cur->ws_info->cfg->fhss.fhss_uc_channel_function == WS_FIXED_CHANNEL) {
35073507
//SET 1 Channel only
35083508
uint16_t channel_number = cur->ws_info->cfg->fhss.fhss_uc_fixed_channel;
3509-
async_req->channel_list.channel_mask[0 + (channel_number / 32)] = 1U << (channel_number % 32);
3509+
async_req->channel_list.channel_mask[channel_number / 32] = 1U << (channel_number % 32);
35103510
} else {
35113511
ws_generate_channel_list(async_req->channel_list.channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
35123512
}

source/6LoWPAN/ws/ws_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int8_t ws_disable_channels_in_range(uint32_t *channel_mask, uint16_t numb
5858
{
5959
for (uint16_t i = 0; i < number_of_channels; i++) {
6060
if (i >= range_start && i <= range_stop) {
61-
channel_mask[0 + (i / 32)] &= ~(1U << (i % 32));
61+
channel_mask[i / 32] &= ~(1U << (i % 32));
6262
}
6363
}
6464
return 0;
@@ -72,7 +72,7 @@ int8_t ws_generate_channel_list(uint32_t *channel_mask, uint16_t number_of_chann
7272
}
7373
// Enable all channels
7474
for (uint16_t i = 0; i < number_of_channels; i++) {
75-
channel_mask[0 + (i / 32)] |= (1U << (i % 32));
75+
channel_mask[i / 32] |= 1U << (i % 32);
7676
}
7777
// Disable unsupported channels per regional frequency bands
7878
if (regulatory_domain == REG_DOMAIN_BZ) {
@@ -102,7 +102,7 @@ uint16_t ws_active_channel_count(uint32_t *channel_mask, uint16_t number_of_chan
102102
uint16_t active_channels = 0;
103103
// Set channel maks outside excluded channels
104104
for (uint16_t i = 0; i < number_of_channels; i++) {
105-
if (channel_mask[0 + (i / 32)] & (1U << (i % 32))) {
105+
if (channel_mask[i / 32] & (1U << (i % 32))) {
106106
active_channels++;
107107
}
108108
}

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static int32_t fhss_channel_index_from_mask(const uint32_t *channel_mask, int32_
292292
int32_t active_channels = 0;
293293
// Set channel maks outside excluded channels
294294
for (int32_t i = 0; i < number_of_channels; i++) {
295-
if (channel_mask[0 + (i / 32)] & (1U << (i % 32))) {
295+
if (channel_mask[i / 32] & (1U << (i % 32))) {
296296
if (channel_index == active_channels) {
297297
return i;
298298
}

0 commit comments

Comments
 (0)