Use hashed set instead of iterating over an array on each sound trigger for checking collision sounds in NACLAntispam
parent
706eade378
commit
5809d34639
|
|
@ -6,6 +6,7 @@
|
|||
#include "llnotificationsutil.h"
|
||||
#include "llviewercontrol.h"
|
||||
#include "llviewerobjectlist.h"
|
||||
#include "sound_ids.h"
|
||||
#include <time.h>
|
||||
|
||||
// NACLAntiSpamQueueEntry
|
||||
|
|
@ -186,6 +187,11 @@ NACLAntiSpamRegistry::NACLAntiSpamRegistry() :
|
|||
{
|
||||
mQueues[queue] = new NACLAntiSpamQueue(mGlobalTime, mGlobalAmount);
|
||||
}
|
||||
|
||||
for (S32 i = 0; i < COLLISION_SOUNDS_SIZE; ++i)
|
||||
{
|
||||
mCollisionSounds.insert(LLUUID(COLLISION_SOUNDS[i]));
|
||||
}
|
||||
}
|
||||
|
||||
NACLAntiSpamRegistry::~NACLAntiSpamRegistry()
|
||||
|
|
@ -493,3 +499,8 @@ void NACLAntiSpamRegistry::purgeGlobalEntries()
|
|||
}
|
||||
mGlobalEntries.clear();
|
||||
}
|
||||
|
||||
bool NACLAntiSpamRegistry::isCollisionSound(const LLUUID& sound_id)
|
||||
{
|
||||
return (mCollisionSounds.find(sound_id) != mCollisionSounds.end());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define NACL_ANTISPAM_H
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include "fscommon.h"
|
||||
#include "lluuid.h"
|
||||
#include "llsingleton.h"
|
||||
|
|
@ -44,6 +45,7 @@ private:
|
|||
};
|
||||
|
||||
typedef boost::unordered_map<LLUUID, NACLAntiSpamQueueEntry*, FSUUIDEntryHasher> t_spam_queue_entry_map;
|
||||
typedef boost::unordered_set<LLUUID, FSUUIDEntryHasher> t_collision_sound_set;
|
||||
|
||||
class NACLAntiSpamQueue
|
||||
{
|
||||
|
|
@ -93,6 +95,8 @@ public:
|
|||
void clearAllQueues();
|
||||
void purgeAllQueues();
|
||||
|
||||
bool isCollisionSound(const LLUUID& sound_id);
|
||||
|
||||
private:
|
||||
NACLAntiSpamRegistry();
|
||||
~NACLAntiSpamRegistry();
|
||||
|
|
@ -110,5 +114,6 @@ private:
|
|||
U32 mGlobalTime;
|
||||
U32 mGlobalAmount;
|
||||
bool mGlobalQueue;
|
||||
t_collision_sound_set mCollisionSounds;
|
||||
};
|
||||
#endif // NACL_ANTISPAM_H
|
||||
|
|
|
|||
|
|
@ -5529,22 +5529,16 @@ void process_sound_trigger(LLMessageSystem *msg, void **)
|
|||
}
|
||||
|
||||
// NaCl - Antispam Registry
|
||||
bool bDoSpamCheck = true;
|
||||
std::string sSound = sound_id.asString();
|
||||
static LLCachedControl<U32> _NACL_AntiSpamSoundMulti(gSavedSettings, "_NACL_AntiSpamSoundMulti");
|
||||
static LLCachedControl<bool> FSPlayCollisionSounds(gSavedSettings, "FSPlayCollisionSounds");
|
||||
for (S32 i = 0; i < COLLISION_SOUNDS_SIZE; i++) //AO: Should probably do this as a hashmap O(1) instead of O(n)
|
||||
if (NACLAntiSpamRegistry::instance().isCollisionSound(sound_id))
|
||||
{
|
||||
if (COLLISION_SOUNDS[i] == sSound)
|
||||
if (!FSPlayCollisionSounds)
|
||||
{
|
||||
if (!FSPlayCollisionSounds)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bDoSpamCheck = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (bDoSpamCheck)
|
||||
else
|
||||
{
|
||||
if (NACLAntiSpamRegistry::instance().checkQueue(ANTISPAM_QUEUE_SOUND, object_id, _NACL_AntiSpamSoundMulti))
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue