message_string_table.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "llerror.h"
00035 #include "message.h"
00036 
00037 inline U32      message_hash_my_string(const char *str)
00038 {
00039         U32 retval = 0;
00040         while (*str++)
00041         {
00042                 retval += *str;
00043                 retval <<= 1;
00044         }
00045         return (retval % MESSAGE_NUMBER_OF_HASH_BUCKETS);
00046 }
00047 
00048 
00049 
00050 LLMessageStringTable::LLMessageStringTable()
00051 :       mUsed(0)
00052 {
00053         for (U32 i = 0; i < MESSAGE_NUMBER_OF_HASH_BUCKETS; i++)
00054         {
00055                 mEmpty[i] = TRUE;
00056                 mString[i][0] = 0;
00057         }
00058 }
00059 
00060 
00061 LLMessageStringTable::~LLMessageStringTable()
00062 { }
00063 
00064 
00065 char* LLMessageStringTable::getString(const char *str)
00066 {
00067         U32 hash_value = message_hash_my_string(str);
00068         while (!mEmpty[hash_value])
00069         {
00070                 if (!strncmp(str, mString[hash_value], MESSAGE_MAX_STRINGS_LENGTH))
00071                 {
00072                         return mString[hash_value];
00073                 }
00074                 else
00075                 {
00076                         hash_value++;
00077                         hash_value %= MESSAGE_NUMBER_OF_HASH_BUCKETS;
00078                 }
00079         }
00080         // not found, so add!
00081         strncpy(mString[hash_value], str, MESSAGE_MAX_STRINGS_LENGTH);  /* Flawfinder: ignore */
00082         mString[hash_value][MESSAGE_MAX_STRINGS_LENGTH - 1] = 0;
00083         mEmpty[hash_value] = FALSE;
00084         mUsed++;
00085         if (mUsed >= MESSAGE_NUMBER_OF_HASH_BUCKETS - 1)
00086         {
00087                 U32 i;
00088                 llinfos << "Dumping string table before crashing on HashTable full!" << llendl;
00089                 for (i = 0; i < MESSAGE_NUMBER_OF_HASH_BUCKETS; i++)
00090                 {
00091                         llinfos << "Entry #" << i << ": " << mString[i] << llendl;
00092                 }
00093         }
00094         return mString[hash_value];
00095 }
00096 

Generated on Fri May 16 08:32:43 2008 for SecondLife by  doxygen 1.5.5