/*\r
* Mesa 3-D graphics library\r
- * Version: 6.3\r
+ * Version: 6.5\r
*\r
- * Copyright (C) 2005 Brian Paul All Rights Reserved.\r
+ * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.\r
*\r
* Permission is hereby granted, free of charge, to any person obtaining a\r
* copy of this software and associated documentation files (the "Software"),\r
#include "imports.h"\r
#include "slang_utility.h"\r
\r
-void slang_alloc_free (void *ptr)\r
+char *slang_string_concat (char *dst, const char *src)\r
{\r
- _mesa_free (ptr);\r
+ return _mesa_strcpy (dst + _mesa_strlen (dst), src);\r
}\r
\r
-void *slang_alloc_malloc (unsigned int size)\r
-{\r
- return _mesa_malloc (size);\r
-}\r
+/* slang_atom_pool */\r
\r
-void *slang_alloc_realloc (void *ptr, unsigned int old_size, unsigned int size)\r
+void slang_atom_pool_construct (slang_atom_pool *pool)\r
{\r
- return _mesa_realloc (ptr, old_size, size);\r
-}\r
+ GLuint i;\r
\r
-int slang_string_compare (const char *str1, const char *str2)\r
-{\r
- return _mesa_strcmp (str1, str2);\r
+ for (i = 0; i < SLANG_ATOM_POOL_SIZE; i++)\r
+ pool->entries[i] = NULL;\r
}\r
\r
-char *slang_string_copy (char *dst, const char *src)\r
+void slang_atom_pool_destruct (slang_atom_pool *pool)\r
{\r
- return _mesa_strcpy (dst, src);\r
-}\r
+ GLuint i;\r
\r
-char *slang_string_concat (char *dst, const char *src)\r
-{\r
- return _mesa_strcpy (dst + _mesa_strlen (dst), src);\r
+ for (i = 0; i < SLANG_ATOM_POOL_SIZE; i++)\r
+ {\r
+ slang_atom_entry *entry;\r
+ \r
+ entry = pool->entries[i];\r
+ while (entry != NULL)\r
+ {\r
+ slang_atom_entry *next;\r
+\r
+ next = entry->next;\r
+ slang_alloc_free (entry->id);\r
+ slang_alloc_free (entry);\r
+ entry = next;\r
+ }\r
+ }\r
}\r
\r
-char *slang_string_duplicate (const char *src)\r
+slang_atom slang_atom_pool_atom (slang_atom_pool *pool, const char *id)\r
{\r
- return _mesa_strdup (src);\r
+ GLuint hash;\r
+ const char *p = id;\r
+ slang_atom_entry **entry;\r
+\r
+ hash = 0;\r
+ while (*p != '\0')\r
+ {\r
+ GLuint g;\r
+\r
+ hash = (hash << 4) + (GLuint) *p++;\r
+ g = hash & 0xf0000000;\r
+ if (g != 0)\r
+ hash ^= g >> 24;\r
+ hash &= ~g;\r
+ }\r
+ hash %= SLANG_ATOM_POOL_SIZE;\r
+\r
+ entry = &pool->entries[hash];\r
+ while (*entry != NULL)\r
+ {\r
+ if (slang_string_compare ((**entry).id, id) == 0)\r
+ return (slang_atom) (**entry).id;\r
+ entry = &(**entry).next;\r
+ }\r
+\r
+ *entry = (slang_atom_entry *) slang_alloc_malloc (sizeof (slang_atom_entry));\r
+ if (*entry == NULL)\r
+ return SLANG_ATOM_NULL;\r
+\r
+ (**entry).next = NULL;\r
+ (**entry).id = slang_string_duplicate (id);\r
+ if ((**entry).id == NULL)\r
+ return SLANG_ATOM_NULL;\r
+ return (slang_atom) (**entry).id;\r
}\r
\r
-unsigned int slang_string_length (const char *str)\r
+const char *slang_atom_pool_id (slang_atom_pool *pool, slang_atom atom)\r
{\r
- return _mesa_strlen (str);\r
+ return (const char *) atom;\r
}\r
\r