summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2005-04-17 20:28:32 +0000
committerBram Moolenaar <Bram@vim.org>2005-04-17 20:28:32 +0000
commit0e21a3f623bc9766953882f30326783f76df39a0 (patch)
tree78dbc51e75c070507ccc9fd5f3e1843be0a8579f /src
parent99942f0b16c36508edf225345483d86901f44c39 (diff)
updated for version 7.0067v7.0067
Diffstat (limited to 'src')
-rw-r--r--src/Makefile8
-rw-r--r--src/globals.h2
-rw-r--r--src/hashtable.c60
-rw-r--r--src/if_python.c11
-rw-r--r--src/main.c7
-rw-r--r--src/proto/hashtable.pro1
-rw-r--r--src/version.h4
7 files changed, 81 insertions, 12 deletions
diff --git a/src/Makefile b/src/Makefile
index 16d3338ecd..f609466c07 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -370,6 +370,8 @@ CClink = $(CC)
# PYTHON
# Uncomment this when you want to include the Python interface.
+# NOTE: This may cause threading to be enabled, which has side effects (such
+# as using different libraries and debugging becomes more difficult).
#CONF_OPT_PYTHON = --enable-pythoninterp
# TCL
@@ -1810,7 +1812,11 @@ installtutor: $(DEST_VIM) $(DEST_RT) $(DEST_TUTOR)
# Install the spell files, if they exist.
installspell: $(DEST_VIM) $(DEST_RT) $(DEST_SPELL)
- if test -f $(SPELLSOURCE)/en.spl; then \
+ if test -f $(SPELLSOURCE)/en.latin1.spl; then \
+ $(INSTALL_DATA) $(SPELLSOURCE)/*.spl $(DEST_SPELL); \
+ chmod $(HELPMOD) $(DEST_SPELL)/*.spl; \
+ fi
+ if test -f $(SPELLSOURCE)/en.utf-8.spl; then \
$(INSTALL_DATA) $(SPELLSOURCE)/*.spl $(DEST_SPELL); \
chmod $(HELPMOD) $(DEST_SPELL)/*.spl; \
fi
diff --git a/src/globals.h b/src/globals.h
index 81c1f7ec79..bbb0f1a697 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -1297,7 +1297,7 @@ EXTERN char_u e_invexpr2[] INIT(=N_("E15: Invalid expression: %s"));
#endif
EXTERN char_u e_invrange[] INIT(=N_("E16: Invalid range"));
EXTERN char_u e_invcmd[] INIT(=N_("E476: Invalid command"));
-#ifdef UNIX
+#if defined(UNIX) || (defined(FEAT_SYN_HL) && defined(FEAT_MBYTE))
EXTERN char_u e_isadir2[] INIT(=N_("E17: \"%s\" is a directory"));
#endif
#ifdef FEAT_LIBCALL
diff --git a/src/hashtable.c b/src/hashtable.c
index 0263f6f73f..a8cd1b7d13 100644
--- a/src/hashtable.c
+++ b/src/hashtable.c
@@ -32,7 +32,10 @@
#if defined(FEAT_EVAL) || defined(FEAT_SYN_HL) || defined(PROTO)
#if 0
-# define HT_DEBUG /* extra checks for table consistency */
+# define HT_DEBUG /* extra checks for table consistency and statistics */
+
+static long hash_count_lookup = 0; /* count number of hashtab lookups */
+static long hash_count_perturb = 0; /* count number of "misses" */
#endif
/* Magic value for algorithm that walks through the array. */
@@ -40,7 +43,7 @@
static int hash_may_resize __ARGS((hashtab_T *ht, int minitems));
-#if defined(FEAT_SYN_HL) || defined(PROTO)
+#if 0 /* currently not used */
/*
* Create an empty hash table.
* Returns NULL when out of memory.
@@ -112,6 +115,10 @@ hash_lookup(ht, key, hash)
hashitem_T *hi;
int idx;
+#ifdef HT_DEBUG
+ ++hash_count_lookup;
+#endif
+
/*
* Quickly handle the most common situations:
* - return if there is no item at all
@@ -141,6 +148,9 @@ hash_lookup(ht, key, hash)
*/
for (perturb = hash; ; perturb >>= PERTURB_SHIFT)
{
+#ifdef HT_DEBUG
+ ++hash_count_perturb; /* count a "miss" for hashtab lookup */
+#endif
idx = (idx << 2) + idx + perturb + 1;
hi = &ht->ht_array[idx & ht->ht_mask];
if (hi->hi_key == NULL)
@@ -155,6 +165,23 @@ hash_lookup(ht, key, hash)
}
/*
+ * Print the efficiency of hashtable lookups.
+ * Useful when trying different hash algorithms.
+ * Called when exiting.
+ */
+ void
+hash_debug_results()
+{
+#ifdef HT_DEBUG
+ fprintf(stderr, "\r\n\r\n\r\n\r\n");
+ fprintf(stderr, "Number of hashtable lookups: %ld\r\n", hash_count_lookup);
+ fprintf(stderr, "Number of perturb loops: %ld\r\n", hash_count_perturb);
+ fprintf(stderr, "Percentage of perturb loops: %ld%%\r\n",
+ hash_count_perturb * 100 / hash_count_lookup);
+#endif
+}
+
+/*
* Add item with key "key" to hashtable "ht".
* Returns FAIL when out of memory or the key is already present.
*/
@@ -332,7 +359,7 @@ hash_may_resize(ht, minitems)
else
{
/* Use specified size. */
- if (minitems < ht->ht_used) /* just in case... */
+ if ((long_u)minitems < ht->ht_used) /* just in case... */
minitems = ht->ht_used;
minsize = minitems * 3 / 2; /* array is up to 2/3 full */
}
@@ -420,16 +447,28 @@ hash_may_resize(ht, minitems)
}
/*
- * Get the hash number for a key. Uses the ElfHash algorithm, which is
- * supposed to have an even distribution (suggested by Charles Campbell).
+ * Get the hash number for a key.
+ * If you think you know a better hash function: Compile with HT_DEBUG set and
+ * run a script that uses hashtables a lot. Vim will then print statistics
+ * when exiting. Try that with the current hash algorithm and yours. The
+ * lower the percentage the better.
*/
hash_T
hash_hash(key)
char_u *key;
{
- hash_T hash = 0;
+ hash_T hash;
+ char_u *p;
+
+ if ((hash = *key) == 0)
+ return (hash_T)0; /* Empty keys are not allowed, but we don't
+ want to crash if we get one. */
+ p = key + 1;
+
+#if 0
+ /* ElfHash algorithm, which is supposed to have an even distribution.
+ * Suggested by Charles Campbell. */
hash_T g;
- char_u *p = key;
while (*p != NUL)
{
@@ -438,6 +477,13 @@ hash_hash(key)
if (g != 0)
hash ^= g >> 24; /* xor g's high 4 bits into hash */
}
+#else
+
+ /* A simplistic algorithm that appears to do very well.
+ * Suggested by George Reilly. */
+ while (*p != NUL)
+ hash = hash * 101 + *p++;
+#endif
return hash;
}
diff --git a/src/if_python.c b/src/if_python.c
index 04a8d179a9..02d6ac18f4 100644
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -115,6 +115,8 @@ struct PyMethodDef { int a; };
# define Py_FindMethod dll_Py_FindMethod
# define Py_InitModule4 dll_Py_InitModule4
# define Py_Initialize dll_Py_Initialize
+# define Py_Finalize dll_Py_Finalize
+# define Py_IsInitialized dll_Py_IsInitialized
# define _PyObject_New dll__PyObject_New
# define _Py_NoneStruct (*dll__Py_NoneStruct)
# define PyObject_Init dll__PyObject_Init
@@ -169,6 +171,8 @@ static PyObject*(*dll_Py_BuildValue)(char *, ...);
static PyObject*(*dll_Py_FindMethod)(struct PyMethodDef[], PyObject *, char *);
static PyObject*(*dll_Py_InitModule4)(char *, struct PyMethodDef *, char *, PyObject *, int);
static void(*dll_Py_Initialize)(void);
+static void(*dll_Py_Finalize)(void);
+static int(*dll_Py_IsInitialized)(void);
static PyObject*(*dll__PyObject_New)(PyTypeObject *, PyObject *);
static PyObject*(*dll__PyObject_Init)(PyObject *, PyTypeObject *);
static PyObject* dll__Py_NoneStruct;
@@ -245,6 +249,8 @@ static struct
{"Py_FindMethod", (PYTHON_PROC*)&dll_Py_FindMethod},
{"Py_InitModule4", (PYTHON_PROC*)&dll_Py_InitModule4},
{"Py_Initialize", (PYTHON_PROC*)&dll_Py_Initialize},
+ {"Py_Finalize", (PYTHON_PROC*)&dll_Py_Finalize},
+ {"Py_IsInitialized", (PYTHON_PROC*)&dll_Py_IsInitialized},
{"_PyObject_New", (PYTHON_PROC*)&dll__PyObject_New},
{"PyObject_Init", (PYTHON_PROC*)&dll__PyObject_Init},
{"_Py_NoneStruct", (PYTHON_PROC*)&dll__Py_NoneStruct},
@@ -423,7 +429,12 @@ static void Python_Release_Vim(void)
python_end()
{
#ifdef DYNAMIC_PYTHON
+ if (hinstPython && Py_IsInitialized())
+ Py_Finalize();
end_dynamic_python();
+#else
+ if (Py_IsInitialized())
+ Py_Finalize();
#endif
}
diff --git a/src/main.c b/src/main.c
index 8e03524d66..eb9aa2863c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,7 +15,7 @@
#include "vim.h"
#ifdef SPAWNO
-# include <spawno.h> /* special MSDOS swapping library */
+# include <spawno.h> /* special MS-DOS swapping library */
#endif
#ifdef HAVE_FCNTL_H
@@ -2312,6 +2312,11 @@ getout(exitval)
#endif
windgoto((int)Rows - 1, 0);
+#if defined(FEAT_EVAL) || defined(FEAT_SYN_HL)
+ /* Optionally print hashtable efficiency. */
+ hash_debug_results();
+#endif
+
#ifdef FEAT_GUI
msg_didany = FALSE;
#endif
diff --git a/src/proto/hashtable.pro b/src/proto/hashtable.pro
index 3a3818ea7b..cacd7a3335 100644
--- a/src/proto/hashtable.pro
+++ b/src/proto/hashtable.pro
@@ -4,6 +4,7 @@ void hash_init __ARGS((hashtab_T *ht));
void hash_clear __ARGS((hashtab_T *ht));
hashitem_T *hash_find __ARGS((hashtab_T *ht, char_u *key));
hashitem_T *hash_lookup __ARGS((hashtab_T *ht, char_u *key, hash_T hash));
+void hash_debug_results __ARGS((void));
int hash_add __ARGS((hashtab_T *ht, char_u *key));
int hash_add_item __ARGS((hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash));
void hash_remove __ARGS((hashtab_T *ht, hashitem_T *hi));
diff --git a/src/version.h b/src/version.h
index 5a8c7c2c24..70630b6dff 100644
--- a/src/version.h
+++ b/src/version.h
@@ -36,5 +36,5 @@
#define VIM_VERSION_NODOT "vim70aa"
#define VIM_VERSION_SHORT "7.0aa"
#define VIM_VERSION_MEDIUM "7.0aa ALPHA"
-#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2005 Apr 15)"
-#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2005 Apr 15, compiled "
+#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2005 Apr 17)"
+#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2005 Apr 17, compiled "