summaryrefslogtreecommitdiffhomepage
path: root/src/ent.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2024-08-03 23:40:31 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2024-08-23 20:37:37 +0100
commit83da606072ce272eb053d4e1497d77e647cfecae (patch)
tree71d0110881ff8685184c5f4ab720cc8d49c24678 /src/ent.c
parentacbd30e0427b16f885f96aed59881ec04eff25bc (diff)
Revise syntax macros and add a ton of branch hints
My new programming style is branch hints. All non-confusing branches must be hinted when I can be bothered. It's faster, sometimes, maybe. Also, start trying to use more signed sizes in at least some of the places where it makes sense. Unsigned sizes are surprisingly error-prone!
Diffstat (limited to 'src/ent.c')
-rw-r--r--src/ent.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/ent.c b/src/ent.c
index a1ad08f..1845b1f 100644
--- a/src/ent.c
+++ b/src/ent.c
@@ -22,6 +22,7 @@
#include "gamedata.h"
#include "gametype.h"
#include "intdefs.h"
+#include "langext.h"
#include "mem.h"
#include "vcall.h"
#include "x86.h"
@@ -35,8 +36,8 @@ static struct edict **edicts = 0;
struct edict *ent_getedict(int idx) {
if (edicts) {
// globalvars->edicts seems to be null when disconnected
- if (!*edicts) return 0;
- return mem_offset(*edicts, sz_edict * idx);
+ if_hot (*edicts) return mem_offset(*edicts, sz_edict * idx);
+ return 0;
}
else {
return PEntityOfEntIndex(engserver, idx);
@@ -45,8 +46,8 @@ struct edict *ent_getedict(int idx) {
void *ent_get(int idx) {
struct edict *e = ent_getedict(idx);
- if (!e) return 0;
- return e->ent_unknown;
+ if_hot(e) return e->ent_unknown;
+ return 0;
}
struct CEntityFactory {
@@ -143,14 +144,14 @@ void **ent_findvtable(const struct CEntityFactory *factory,
const char *classname) {
#ifdef _WIN32
ctor_func ctor = findctor(factory, classname);
- if (!ctor) return 0;
+ if_cold (!ctor) return 0;
const uchar *insns = (const uchar *)ctor;
// the constructor itself should do *(void**)this = &vtable; almost right
// away, so look for the first immediate load into indirect register
for (const uchar *p = insns; p - insns < 32;) {
if (p[0] == X86_MOVMIW && (p[1] & 0xF8) == 0) return mem_loadptr(p + 2);
int len = x86_len(p);
- if (len == -1) {
+ if_cold (len == -1) {
errmsg_errorx("unknown or invalid instruction looking for %s "
"vtable pointer", classname);
return 0;
@@ -166,7 +167,8 @@ void **ent_findvtable(const struct CEntityFactory *factory,
INIT {
#ifdef _WIN32 // TODO(linux): above
struct con_cmd *dumpentityfactories = con_findcmd("dumpentityfactories");
- if (!dumpentityfactories || !find_entfactorydict(dumpentityfactories->cb)) {
+ if_cold (!dumpentityfactories ||
+ !find_entfactorydict(dumpentityfactories->cb)) {
errmsg_warnx("server entity factories unavailable");
}
#endif