From 9b23b68f560715b3c44b00f28237c054150c0c90 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sun, 8 Apr 2018 21:59:35 +1000 Subject: [PATCH] Models: cache .model_str() result, reduces fexists calls --- qcsrc/common/models/model.qh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/qcsrc/common/models/model.qh b/qcsrc/common/models/model.qh index 7a1e7d73c..38aa4e33a 100644 --- a/qcsrc/common/models/model.qh +++ b/qcsrc/common/models/model.qh @@ -1,10 +1,9 @@ #pragma once -#define setmodel(e, m) _setmodel((e), (m).model_str()) - CLASS(Model, Object) ATTRIB(Model, m_id, int, 0); ATTRIB(Model, model_str, string()); + ATTRIB(Model, model_str_, string); CONSTRUCTOR(Model, string() path) { CONSTRUCT(Model); @@ -20,5 +19,12 @@ CLASS(Model, Object) } profile(sprintf("precache_model(\"%s\")", s)); precache_model(s); + strcpy(this.model_str_, s); } ENDCLASS(Model) + +#define setmodel(this, m) MACRO_BEGIN \ + Model _setmodel_model = (m); \ + string _setmodel_cached = _setmodel_model.model_str_; \ + _setmodel((this), _setmodel_cached ? _setmodel_cached : _setmodel_model.model_str()); \ +MACRO_END -- 2.39.2