Skip to content

Commit 10a324a

Browse files
authored
Reduce cost of joint lookups by reducing string allocations via use of std::string_view and heterogeneous map lookups (secondlife#3970)
1 parent 3e5f4fd commit 10a324a

20 files changed

+66
-68
lines changed

indra/llappearance/llavatarappearance.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class LLAvatarAppearance : public LLCharacter
138138
LLVector3 mHeadOffset{}; // current head position
139139
LLAvatarJoint* mRoot{ nullptr };
140140

141-
typedef std::map<std::string, LLJoint*> joint_map_t;
141+
typedef std::map<std::string, LLJoint*, std::less<>> joint_map_t;
142142
joint_map_t mJointMap;
143143

144144
typedef std::map<std::string, LLVector3> joint_state_map_t;
@@ -151,7 +151,7 @@ class LLAvatarAppearance : public LLCharacter
151151
public:
152152
typedef std::vector<LLAvatarJoint*> avatar_joint_list_t;
153153
const avatar_joint_list_t& getSkeleton() { return mSkeleton; }
154-
typedef std::map<std::string, std::string> joint_alias_map_t;
154+
typedef std::map<std::string, std::string, std::less<>> joint_alias_map_t;
155155
const joint_alias_map_t& getJointAliases();
156156

157157

indra/llcharacter/llbvhloader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ LLQuaternion::Order bvhStringToOrder( char *str )
131131
// LLBVHLoader()
132132
//-----------------------------------------------------------------------------
133133

134-
LLBVHLoader::LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string>& joint_alias_map )
134+
LLBVHLoader::LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string, std::less<>>& joint_alias_map )
135135
{
136136
reset();
137137
errorLine = 0;

indra/llcharacter/llbvhloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class LLBVHLoader
227227
friend class LLKeyframeMotion;
228228
public:
229229
// Constructor
230-
LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string>& joint_alias_map );
230+
LLBVHLoader(const char* buffer, ELoadStatus &loadStatus, S32 &errorLine, std::map<std::string, std::string, std::less<>>& joint_alias_map );
231231
~LLBVHLoader();
232232

233233
/*

indra/llcharacter/llcharacter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ LLCharacter::~LLCharacter()
7777
//-----------------------------------------------------------------------------
7878
// getJoint()
7979
//-----------------------------------------------------------------------------
80-
LLJoint *LLCharacter::getJoint( const std::string &name )
80+
LLJoint* LLCharacter::getJoint(std::string_view name)
8181
{
82-
LLJoint* joint = NULL;
82+
LLJoint* joint = nullptr;
8383

84-
LLJoint *root = getRootJoint();
85-
if (root)
84+
if (LLJoint* root = getRootJoint())
8685
{
8786
joint = root->findJoint(name);
8887
}

indra/llcharacter/llcharacter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class LLCharacter
7676
// get the specified joint
7777
// default implementation does recursive search,
7878
// subclasses may optimize/cache results.
79-
virtual LLJoint *getJoint( const std::string &name );
79+
virtual LLJoint* getJoint(std::string_view name);
8080

8181
// get the position of the character
8282
virtual LLVector3 getCharacterPosition() = 0;

indra/llcharacter/lljoint.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,21 +242,20 @@ LLJoint *LLJoint::getRoot()
242242
//-----------------------------------------------------------------------------
243243
// findJoint()
244244
//-----------------------------------------------------------------------------
245-
LLJoint *LLJoint::findJoint( const std::string &name )
245+
LLJoint* LLJoint::findJoint(std::string_view name)
246246
{
247247
if (name == getName())
248248
return this;
249249

250250
for (LLJoint* joint : mChildren)
251251
{
252-
LLJoint *found = joint->findJoint(name);
253-
if (found)
252+
if (LLJoint* found = joint->findJoint(name))
254253
{
255254
return found;
256255
}
257256
}
258257

259-
return NULL;
258+
return nullptr;
260259
}
261260

262261

indra/llcharacter/lljoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class LLJoint
222222
LLJoint *getRoot();
223223

224224
// search for child joints by name
225-
LLJoint *findJoint( const std::string &name );
225+
LLJoint* findJoint(std::string_view name);
226226

227227
// add/remove children
228228
void addChild( LLJoint *joint );

indra/llprimitive/lldaeloader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ LLDAELoader::LLDAELoader(
880880
void* opaque_userdata,
881881
JointTransformMap& jointTransformMap,
882882
JointNameSet& jointsFromNodes,
883-
std::map<std::string, std::string>& jointAliasMap,
883+
std::map<std::string, std::string, std::less<>>& jointAliasMap,
884884
U32 maxJointsPerMesh,
885885
U32 modelLimit,
886886
bool preprocess)

indra/llprimitive/lldaeloader.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ class LLDAELoader : public LLModelLoader
4747
dae_model_map mModelsMap;
4848

4949
LLDAELoader(
50-
std::string filename,
51-
S32 lod,
52-
LLModelLoader::load_callback_t load_cb,
53-
LLModelLoader::joint_lookup_func_t joint_lookup_func,
54-
LLModelLoader::texture_load_func_t texture_load_func,
55-
LLModelLoader::state_callback_t state_cb,
56-
void* opaque_userdata,
57-
JointTransformMap& jointTransformMap,
58-
JointNameSet& jointsFromNodes,
59-
std::map<std::string, std::string>& jointAliasMap,
60-
U32 maxJointsPerMesh,
61-
U32 modelLimit,
62-
bool preprocess);
50+
std::string filename,
51+
S32 lod,
52+
LLModelLoader::load_callback_t load_cb,
53+
LLModelLoader::joint_lookup_func_t joint_lookup_func,
54+
LLModelLoader::texture_load_func_t texture_load_func,
55+
LLModelLoader::state_callback_t state_cb,
56+
void* opaque_userdata,
57+
JointTransformMap& jointTransformMap,
58+
JointNameSet& jointsFromNodes,
59+
std::map<std::string, std::string, std::less<>>& jointAliasMap,
60+
U32 maxJointsPerMesh,
61+
U32 modelLimit,
62+
bool preprocess);
6363
virtual ~LLDAELoader() ;
6464

6565
virtual bool OpenFile(const std::string& filename);

indra/llprimitive/llgltfloader.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ static const std::string lod_suffix[LLModel::NUM_LODS] =
6666
};
6767

6868

69-
LLGLTFLoader::LLGLTFLoader(std::string filename,
70-
S32 lod,
71-
LLModelLoader::load_callback_t load_cb,
72-
LLModelLoader::joint_lookup_func_t joint_lookup_func,
73-
LLModelLoader::texture_load_func_t texture_load_func,
74-
LLModelLoader::state_callback_t state_cb,
75-
void * opaque_userdata,
76-
JointTransformMap & jointTransformMap,
77-
JointNameSet & jointsFromNodes,
78-
std::map<std::string, std::string> &jointAliasMap,
79-
U32 maxJointsPerMesh,
80-
U32 modelLimit) //,
81-
//bool preprocess)
69+
LLGLTFLoader::LLGLTFLoader(std::string filename,
70+
S32 lod,
71+
LLModelLoader::load_callback_t load_cb,
72+
LLModelLoader::joint_lookup_func_t joint_lookup_func,
73+
LLModelLoader::texture_load_func_t texture_load_func,
74+
LLModelLoader::state_callback_t state_cb,
75+
void * opaque_userdata,
76+
JointTransformMap & jointTransformMap,
77+
JointNameSet & jointsFromNodes,
78+
std::map<std::string, std::string, std::less<>> & jointAliasMap,
79+
U32 maxJointsPerMesh,
80+
U32 modelLimit) //,
81+
//bool preprocess)
8282
: LLModelLoader( filename,
8383
lod,
8484
load_cb,

0 commit comments

Comments
 (0)