[gnome-builder] highlight: add overly simplistic index helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] highlight: add overly simplistic index helper
- Date: Fri, 27 Mar 2015 00:38:35 +0000 (UTC)
commit 719fb590a3d307e0acd60e4916177c9fb2b80eea
Author: Christian Hergert <christian hergert me>
Date: Thu Mar 26 13:01:55 2015 -0700
highlight: add overly simplistic index helper
libide/Makefile.am | 2 +
libide/ide-highlight-index.c | 96 ++++++++++++++++++++++++++++++++++++++++++
libide/ide-highlight-index.h | 39 +++++++++++++++++
3 files changed, 137 insertions(+), 0 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 75a5230..31ad112 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -227,6 +227,8 @@ libide_1_0_la_SOURCES = \
libide/git/ide-git-search-index.h \
libide/gsettings/ide-language-defaults.c \
libide/gsettings/ide-language-defaults.h \
+ libide/ide-highlight-index.c \
+ libide/ide-highlight-index.h \
libide/ide-async-helper.c \
libide/ide-async-helper.h \
libide/ide-battery-monitor.c \
diff --git a/libide/ide-highlight-index.c b/libide/ide-highlight-index.c
new file mode 100644
index 0000000..03e79d6
--- /dev/null
+++ b/libide/ide-highlight-index.c
@@ -0,0 +1,96 @@
+/* ide-highlight-index.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/user.h>
+
+#include "ide-highlight-index.h"
+
+struct _IdeHighlightIndex
+{
+ volatile gint ref_count;
+ GStringChunk *strings;
+ GHashTable *index;
+};
+
+IdeHighlightIndex *
+ide_highlight_index_new (void)
+{
+ IdeHighlightIndex *ret;
+
+ ret = g_new0 (IdeHighlightIndex, 1);
+ ret->ref_count = 1;
+ ret->strings = g_string_chunk_new (PAGE_SIZE);
+ ret->index = g_hash_table_new (g_str_hash, g_str_equal);
+
+ return ret;
+}
+
+void
+ide_highlight_index_insert (IdeHighlightIndex *self,
+ const gchar *word,
+ IdeHighlightKind kind)
+{
+ gchar *key;
+
+ g_assert (self);
+ g_assert (word);
+ g_assert (kind != IDE_HIGHLIGHT_KIND_NONE);
+
+ if (g_hash_table_contains (self->index, word))
+ return;
+
+ key = g_string_chunk_insert (self->strings, word);
+ g_hash_table_insert (self->index, key, GINT_TO_POINTER (kind));
+}
+
+IdeHighlightKind
+ide_highlight_index_lookup (IdeHighlightIndex *self,
+ const gchar *word)
+{
+ gpointer value;
+
+ g_assert (self);
+ g_assert (word);
+
+ value = g_hash_table_lookup (self->index, word);
+
+ return GPOINTER_TO_INT (value);
+}
+
+IdeHighlightIndex *
+ide_highlight_index_ref (IdeHighlightIndex *self)
+{
+ g_assert (self);
+ g_assert_cmpint (self->ref_count, >, 0);
+
+ return self;
+}
+
+void
+ide_highlight_index_unref (IdeHighlightIndex *self)
+{
+ g_assert (self);
+ g_assert_cmpint (self->ref_count, >, 0);
+
+ if (g_atomic_int_dec_and_test (&self->ref_count))
+ {
+ g_string_chunk_free (self->strings);
+ g_hash_table_unref (self->index);
+ g_free (self);
+ }
+}
diff --git a/libide/ide-highlight-index.h b/libide/ide-highlight-index.h
new file mode 100644
index 0000000..6a0887c
--- /dev/null
+++ b/libide/ide-highlight-index.h
@@ -0,0 +1,39 @@
+/* ide-highlight-index.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_HIGHLIGHT_INDEX_H
+#define IDE_HIGHLIGHT_INDEX_H
+
+#include "ide-highlighter.h"
+
+G_BEGIN_DECLS
+
+typedef struct _IdeHighlightIndex IdeHighlightIndex;
+
+IdeHighlightIndex *ide_highlight_index_new (void);
+IdeHighlightIndex *ide_highlight_index_ref (IdeHighlightIndex *self);
+void ide_highlight_index_unref (IdeHighlightIndex *self);
+void ide_highlight_index_insert (IdeHighlightIndex *self,
+ const gchar *word,
+ IdeHighlightKind kind);
+IdeHighlightKind ide_highlight_index_lookup (IdeHighlightIndex *self,
+ const gchar *word);
+
+G_END_DECLS
+
+#endif /* IDE_HIGHLIGHT_INDEX_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]