Use static maps to convert input events
This improves readability (hopefully). PR #2831 <https://github.com/Genymobile/scrcpy/pull/2831>
This commit is contained in:
13
app/src/util/intmap.c
Normal file
13
app/src/util/intmap.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "intmap.h"
|
||||
|
||||
const struct sc_intmap_entry *
|
||||
sc_intmap_find_entry(const struct sc_intmap_entry entries[], size_t len,
|
||||
int32_t key) {
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
const struct sc_intmap_entry *entry = &entries[i];
|
||||
if (entry->key == key) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
24
app/src/util/intmap.h
Normal file
24
app/src/util/intmap.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef SC_ARRAYMAP_H
|
||||
#define SC_ARRAYMAP_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct sc_intmap_entry {
|
||||
int32_t key;
|
||||
int32_t value;
|
||||
};
|
||||
|
||||
const struct sc_intmap_entry *
|
||||
sc_intmap_find_entry(const struct sc_intmap_entry entries[], size_t len,
|
||||
int32_t key);
|
||||
|
||||
/**
|
||||
* MAP is expected to be a static array of sc_intmap_entry, so that
|
||||
* ARRAY_LEN(MAP) can be computed statically.
|
||||
*/
|
||||
#define SC_INTMAP_FIND_ENTRY(MAP, KEY) \
|
||||
sc_intmap_find_entry(MAP, ARRAY_LEN(MAP), KEY)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user