summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Janik <timj@gtk.org>1998-06-02 01:11:17 +0000
committerTim Janik <timj@src.gnome.org>1998-06-02 01:11:17 +0000
commit88e84f52dde0b6e1d901d1f5ffc5378612f83269 (patch)
treebbd2c883b4121f33390f76f70209ccc1f76c3882
parent8a6a8c7bc32a39f8369eb9408ef3313e0be87c29 (diff)
downloadgtk+-88e84f52dde0b6e1d901d1f5ffc5378612f83269.tar.gz
wrote a comment describing why a hash node's key should not also get
Mon Jun 1 04:43:27 1998 Tim Janik <timj@gtk.org> * ghash.c (g_hash_table_insert): wrote a comment describing why a hash node's key should not also get replaced when overriding previous entries. Tue May 26 18:30:06 1998 Tim Janik <timj@gtk.org> * glib.h (g_string_sized_new): new function to controll the preallocated size of a GString. * glib.h (g_strreversed): new function to reverse a string.
-rw-r--r--glib/ChangeLog13
-rw-r--r--glib/ghash.c7
-rw-r--r--glib/glib.h4
-rw-r--r--glib/gscanner.c20
-rw-r--r--glib/gstring.c23
-rw-r--r--glib/gutils.c25
6 files changed, 86 insertions, 6 deletions
diff --git a/glib/ChangeLog b/glib/ChangeLog
index 247319f3e9..907b5455c2 100644
--- a/glib/ChangeLog
+++ b/glib/ChangeLog
@@ -1,3 +1,16 @@
+Mon Jun 1 04:43:27 1998 Tim Janik <timj@gtk.org>
+
+ * ghash.c (g_hash_table_insert): wrote a comment describing why
+ a hash node's key should not also get replaced when overriding
+ previous entries.
+
+Tue May 26 18:30:06 1998 Tim Janik <timj@gtk.org>
+
+ * glib.h (g_string_sized_new): new function to controll the preallocated
+ size of a GString.
+
+ * glib.h (g_strreversed): new function to reverse a string.
+
Mon May 18 22:14:39 1998 Owen Taylor <otaylor@gtk.org>
(Yasuhiro SHIRASAKI <joke@awa.tohoku.ac.jp> : gtk-joke-980517-0.patch)
diff --git a/glib/ghash.c b/glib/ghash.c
index 6b2e50f1f8..90ee2afea8 100644
--- a/glib/ghash.c
+++ b/glib/ghash.c
@@ -122,6 +122,13 @@ g_hash_table_insert (GHashTable *hash_table,
(* rhash_table->key_compare_func) (node->key, key)) ||
(node->key == key))
{
+ /* do not reset node->key in this place, keeping
+ * the old key might be intended.
+ * a g_hash_table_remove/g_hash_table_insert pair
+ * can be used otherwise.
+ *
+ * node->key = key;
+ */
node->value = value;
return;
}
diff --git a/glib/glib.h b/glib/glib.h
index 4e3dce215e..78688c5fbe 100644
--- a/glib/glib.h
+++ b/glib/glib.h
@@ -752,6 +752,7 @@ gint g_strcasecmp (const gchar *s1,
const gchar *s2);
void g_strdown (gchar *string);
void g_strup (gchar *string);
+void g_strreverse (gchar *string);
guint g_parse_debug_string (const gchar *string,
GDebugKey *keys,
guint nkeys);
@@ -795,6 +796,7 @@ gchar* g_string_chunk_insert_const (GStringChunk *chunk,
/* Strings
*/
GString* g_string_new (const gchar *init);
+GString* g_string_sized_new (guint dfl_size);
void g_string_free (GString *string,
gint free_segment);
GString* g_string_assign (GString *lval,
@@ -1060,6 +1062,8 @@ void g_scanner_foreach_symbol (GScanner *scanner,
gpointer func_data);
void g_scanner_remove_symbol (GScanner *scanner,
const gchar *symbol);
+void g_scanner_freeze_symbol_table (GScanner *scanner);
+void g_scanner_thaw_symbol_table (GScanner *scanner);
void g_scanner_unexp_token (GScanner *scanner,
GTokenType expected_token,
const gchar *identifier_spec,
diff --git a/glib/gscanner.c b/glib/gscanner.c
index d8f7f6805a..56f621ea35 100644
--- a/glib/gscanner.c
+++ b/glib/gscanner.c
@@ -347,8 +347,8 @@ g_scanner_add_symbol (GScanner *scanner,
{
register GScannerHashVal *hash_val;
- g_return_if_fail (symbol != NULL);
g_return_if_fail (scanner != NULL);
+ g_return_if_fail (symbol != NULL);
hash_val = g_scanner_lookup_internal (scanner, symbol);
@@ -429,6 +429,8 @@ g_scanner_remove_symbol (GScanner *scanner,
{
register GScannerHashVal *hash_val;
+ g_return_if_fail (scanner != NULL);
+
hash_val = g_scanner_lookup_internal (scanner, symbol);
if (hash_val)
@@ -439,6 +441,22 @@ g_scanner_remove_symbol (GScanner *scanner,
}
}
+void
+g_scanner_freeze_symbol_table (GScanner *scanner)
+{
+ g_return_if_fail (scanner != NULL);
+
+ g_hash_table_freeze (scanner->symbol_table);
+}
+
+void
+g_scanner_thaw_symbol_table (GScanner *scanner)
+{
+ g_return_if_fail (scanner != NULL);
+
+ g_hash_table_thaw (scanner->symbol_table);
+}
+
GTokenType
g_scanner_peek_next_token (GScanner *scanner)
{
diff --git a/glib/gstring.c b/glib/gstring.c
index 91a5e1e2c9..df3fdb5009 100644
--- a/glib/gstring.c
+++ b/glib/gstring.c
@@ -205,7 +205,7 @@ g_string_maybe_expand (GRealString* string, gint len)
}
GString*
-g_string_new (const gchar *init)
+g_string_sized_new (guint dfl_size)
{
GRealString *string;
@@ -216,16 +216,29 @@ g_string_new (const gchar *init)
string = g_chunk_new (GRealString, string_mem_chunk);
- string->alloc = 2;
+ string->alloc = 0;
string->len = 0;
- string->str = g_new0(char, 2);
+ string->str = NULL;
- if (init)
- g_string_append ((GString*)string, init);
+ g_string_maybe_expand (string, MAX (dfl_size, 2));
+ string->str[0] = 0;
return (GString*) string;
}
+GString*
+g_string_new (const gchar *init)
+{
+ GString *string;
+
+ string = g_string_sized_new (2);
+
+ if (init)
+ g_string_append (string, init);
+
+ return string;
+}
+
void
g_string_free (GString *string,
gint free_segment)
diff --git a/glib/gutils.c b/glib/gutils.c
index c97f408bf4..321501827a 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -731,6 +731,31 @@ g_strup (gchar *string)
}
}
+void
+g_strreverse (gchar *string)
+{
+ g_return_if_fail (string != NULL);
+
+ if (*string)
+ {
+ register gchar *h, *t;
+
+ h = string;
+ t = string + strlen (string) - 1;
+
+ while (h < t)
+ {
+ register gchar c;
+
+ c = *h;
+ *h = *t;
+ h++;
+ *t = c;
+ t--;
+ }
+ }
+}
+
gint
g_strcasecmp (const gchar *s1,
const gchar *s2)