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 LLMessageStringTable gMessageStringTable;
00050 
00051 
00052 LLMessageStringTable::LLMessageStringTable()
00053 :       mUsed(0)
00054 {
00055         for (U32 i = 0; i < MESSAGE_NUMBER_OF_HASH_BUCKETS; i++)
00056         {
00057                 mEmpty[i] = TRUE;
00058                 mString[i][0] = 0;
00059         }
00060 }
00061 
00062 
00063 LLMessageStringTable::~LLMessageStringTable()
00064 { }
00065 
00066 
00067 char* LLMessageStringTable::getString(const char *str)
00068 {
00069         U32 hash_value = message_hash_my_string(str);
00070         while (!mEmpty[hash_value])
00071         {
00072                 if (!strncmp(str, mString[hash_value], MESSAGE_MAX_STRINGS_LENGTH))
00073                 {
00074                         return mString[hash_value];
00075                 }
00076                 else
00077                 {
00078                         hash_value++;
00079                         hash_value %= MESSAGE_NUMBER_OF_HASH_BUCKETS;
00080                 }
00081         }
00082         // not found, so add!
00083         strncpy(mString[hash_value], str, MESSAGE_MAX_STRINGS_LENGTH);  /* Flawfinder: ignore */
00084         mString[hash_value][MESSAGE_MAX_STRINGS_LENGTH - 1] = 0;
00085         mEmpty[hash_value] = FALSE;
00086         mUsed++;
00087         if (mUsed >= MESSAGE_NUMBER_OF_HASH_BUCKETS - 1)
00088         {
00089                 U32 i;
00090                 llinfos << "Dumping string table before crashing on HashTable full!" << llendl;
00091                 for (i = 0; i < MESSAGE_NUMBER_OF_HASH_BUCKETS; i++)
00092                 {
00093                         llinfos << "Entry #" << i << ": " << mString[i] << llendl;
00094                 }
00095         }
00096         return mString[hash_value];
00097 }
00098 

Generated on Thu Jul 1 06:09:56 2010 for Second Life Viewer by  doxygen 1.4.7