mirror of
https://github.com/swaywm/sway.git
synced 2026-04-30 06:46:24 -04:00
use standard ARRAY_SIZE() macro
Replace all the custom `sizeof(array)/sizeof(element)` and `sizeof(array)/sizeof(type)` with the standard macro ARRAY_SIZE().
This commit is contained in:
parent
5f8676f214
commit
021933f735
14 changed files with 33 additions and 23 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "unicode.h"
|
||||
#include "util.h"
|
||||
|
||||
size_t utf8_chsize(uint32_t ch) {
|
||||
if (ch < 0x80) {
|
||||
|
|
@ -92,7 +93,7 @@ static const struct {
|
|||
|
||||
int utf8_size(const char *s) {
|
||||
uint8_t c = (uint8_t)*s;
|
||||
for (size_t i = 0; i < sizeof(sizes) / sizeof(*sizes); ++i) {
|
||||
for (size_t i = 0; i < ARRAY_SIZE(sizes); ++i) {
|
||||
if ((c & sizes[i].mask) == sizes[i].result) {
|
||||
return sizes[i].octets;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ static struct modifier_key {
|
|||
|
||||
uint32_t get_modifier_mask_by_name(const char *name) {
|
||||
int i;
|
||||
for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) {
|
||||
for (i = 0; i < (int)(ARRAY_SIZE(modifiers)); ++i) {
|
||||
if (strcasecmp(modifiers[i].name, name) == 0) {
|
||||
return modifiers[i].mod;
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ uint32_t get_modifier_mask_by_name(const char *name) {
|
|||
|
||||
const char *get_modifier_name_by_mask(uint32_t modifier) {
|
||||
int i;
|
||||
for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) {
|
||||
for (i = 0; i < (int)(ARRAY_SIZE(modifiers)); ++i) {
|
||||
if (modifiers[i].mod == modifier) {
|
||||
return modifiers[i].name;
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ const char *get_modifier_name_by_mask(uint32_t modifier) {
|
|||
int get_modifier_names(const char **names, uint32_t modifier_masks) {
|
||||
int length = 0;
|
||||
int i;
|
||||
for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) {
|
||||
for (i = 0; i < (int)(ARRAY_SIZE(modifiers)); ++i) {
|
||||
if ((modifier_masks & modifiers[i].mod) != 0) {
|
||||
names[length] = modifiers[i].name;
|
||||
++length;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue