]> git.pld-linux.org Git - packages/vim.git/blob - 7.3.143
- new: 7.3.252
[packages/vim.git] / 7.3.143
1 To: vim_dev@googlegroups.com
2 Subject: Patch 7.3.143
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.3.143
11 Problem:    Memfile is not tested sufficiently.  Looking up blocks in a
12             memfile is slow when there are many blocks.
13 Solution:   Add high level test and unittest.  Adjust the number of hash
14             buckets to the number of blocks.  (Ivan Krasilnikov)
15 Files:      Filelist, src/Makefile, src/main.c, src/memfile.c,
16             src/memfile_test.c src/structs.h src/testdir/Make_amiga.mak,
17             src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
18             src/testdir/Make_os2.mak, src/testdir/Make_vms.mak,
19             src/testdir/Makefile, src/testdir/test77.in, src/testdir/test77.ok
20
21
22 *** ../vim-7.3.142/Filelist     2010-08-15 21:57:20.000000000 +0200
23 --- Filelist    2011-03-22 17:39:22.000000000 +0100
24 ***************
25 *** 39,44 ****
26 --- 39,45 ----
27                 src/mark.c \
28                 src/mbyte.c \
29                 src/memfile.c \
30 +               src/memfile_test.c \
31                 src/memline.c \
32                 src/menu.c \
33                 src/message.c \
34 ***************
35 *** 686,691 ****
36 --- 687,694 ----
37                 runtime/tutor/tutor.utf-8 \
38                 runtime/tutor/tutor.?? \
39                 runtime/tutor/tutor.??.* \
40 +               runtime/tutor/tutor.bar \
41 +               runtime/tutor/tutor.bar.* \
42                 runtime/spell/README.txt \
43                 runtime/spell/??/*.diff \
44                 runtime/spell/??/main.aap \
45 *** ../vim-7.3.142/src/Makefile 2011-02-15 15:27:00.000000000 +0100
46 --- src/Makefile        2011-03-22 18:07:25.000000000 +0100
47 ***************
48 *** 561,567 ****
49   #CFLAGS = -g -O2 '-DSTARTUPTIME="vimstartup"' -fno-strength-reduce -Wall -Wmissing-prototypes
50   
51   # Use this with GCC to check for mistakes, unused arguments, etc.
52 ! #CFLAGS = -g -Wall -Wextra -Wmissing-prototypes -Wunreachable-code -D_FORTIFY_SOURCE=1 -DU_DEBUG
53   #CFLAGS = -g -O2 -Wall -Wextra -Wmissing-prototypes -D_FORTIFY_SOURCE=1 -DU_DEBUG
54   #PYTHON_CFLAGS_EXTRA = -Wno-missing-field-initializers
55   #MZSCHEME_CFLAGS_EXTRA = -Wno-unreachable-code -Wno-unused-parameter
56 --- 561,567 ----
57   #CFLAGS = -g -O2 '-DSTARTUPTIME="vimstartup"' -fno-strength-reduce -Wall -Wmissing-prototypes
58   
59   # Use this with GCC to check for mistakes, unused arguments, etc.
60 ! #CFLAGS = -g -Wall -Wextra -Wmissing-prototypes -Wunreachable-code -D_FORTIFY_SOURCE=1
61   #CFLAGS = -g -O2 -Wall -Wextra -Wmissing-prototypes -D_FORTIFY_SOURCE=1 -DU_DEBUG
62   #PYTHON_CFLAGS_EXTRA = -Wno-missing-field-initializers
63   #MZSCHEME_CFLAGS_EXTRA = -Wno-unreachable-code -Wno-unused-parameter
64 ***************
65 *** 594,601 ****
66   
67   # PROFILING - Uncomment the next two lines to do profiling with gcc and gprof.
68   # Might not work with GUI or Perl.
69 ! # For unknown reasons adding "-lc" fixes a linking problem with GCC.  That's
70 ! # probably a bug in the "-pg" implementation.
71   # Need to recompile everything after changing this: "make clean" "make".
72   #PROFILE_CFLAGS = -pg -g -DWE_ARE_PROFILING
73   #PROFILE_LIBS = -pg
74 --- 594,602 ----
75   
76   # PROFILING - Uncomment the next two lines to do profiling with gcc and gprof.
77   # Might not work with GUI or Perl.
78 ! # For unknown reasons adding "-lc" fixes a linking problem with some versions
79 ! # of GCC.  That's probably a bug in the "-pg" implementation.
80 ! # After running Vim see the profile result with: gmon vim gmon.out | vim -
81   # Need to recompile everything after changing this: "make clean" "make".
82   #PROFILE_CFLAGS = -pg -g -DWE_ARE_PROFILING
83   #PROFILE_LIBS = -pg
84 ***************
85 *** 606,613 ****
86   # Configuration is in the .ccmalloc or ~/.ccmalloc file.
87   # Doesn't work very well, since memory linked to from global variables
88   # (in libraries) is also marked as leaked memory.
89 ! #PROFILE_CFLAGS = -DEXITFREE
90 ! #PROFILE_LIBS = -lccmalloc
91   
92   #####################################################
93   ###  Specific systems, check if yours is listed!  ### {{{
94 --- 607,614 ----
95   # Configuration is in the .ccmalloc or ~/.ccmalloc file.
96   # Doesn't work very well, since memory linked to from global variables
97   # (in libraries) is also marked as leaked memory.
98 ! #LEAK_CFLAGS = -DEXITFREE
99 ! #LEAK_LIBS = -lccmalloc
100   
101   #####################################################
102   ###  Specific systems, check if yours is listed!  ### {{{
103 ***************
104 *** 1329,1335 ****
105   PRE_DEFS = -Iproto $(DEFS) $(GUI_DEFS) $(GUI_IPATH) $(CPPFLAGS) $(EXTRA_IPATHS)
106   POST_DEFS = $(X_CFLAGS) $(MZSCHEME_CFLAGS) $(TCL_CFLAGS) $(EXTRA_DEFS)
107   
108 ! ALL_CFLAGS = $(PRE_DEFS) $(CFLAGS) $(PROFILE_CFLAGS) $(POST_DEFS)
109   
110   # Exclude $CFLAGS for osdef.sh, for Mac 10.4 some flags don't work together
111   # with "-E".
112 --- 1330,1336 ----
113   PRE_DEFS = -Iproto $(DEFS) $(GUI_DEFS) $(GUI_IPATH) $(CPPFLAGS) $(EXTRA_IPATHS)
114   POST_DEFS = $(X_CFLAGS) $(MZSCHEME_CFLAGS) $(TCL_CFLAGS) $(EXTRA_DEFS)
115   
116 ! ALL_CFLAGS = $(PRE_DEFS) $(CFLAGS) $(PROFILE_CFLAGS) $(LEAK_CFLAGS) $(POST_DEFS)
117   
118   # Exclude $CFLAGS for osdef.sh, for Mac 10.4 some flags don't work together
119   # with "-E".
120 ***************
121 *** 1358,1364 ****
122            $(PYTHON3_LIBS) \
123            $(TCL_LIBS) \
124            $(RUBY_LIBS) \
125 !          $(PROFILE_LIBS)
126   
127   # abbreviations
128   DEST_BIN = $(DESTDIR)$(BINDIR)
129 --- 1359,1366 ----
130            $(PYTHON3_LIBS) \
131            $(TCL_LIBS) \
132            $(RUBY_LIBS) \
133 !          $(PROFILE_LIBS) \
134 !          $(LEAK_LIBS)
135   
136   # abbreviations
137   DEST_BIN = $(DESTDIR)$(BINDIR)
138 ***************
139 *** 1480,1487 ****
140             if_python.c if_python3.c if_tcl.c if_ruby.c if_sniff.c \
141             gui_beval.c workshop.c wsdebug.c integration.c netbeans.c
142   
143   # All sources, also the ones that are not configured
144 ! ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(EXTRA_SRC)
145   
146   # Which files to check with lint.  Select one of these three lines.  ALL_SRC
147   # checks more, but may not work well for checking a GUI that wasn't configured.
148 --- 1482,1496 ----
149             if_python.c if_python3.c if_tcl.c if_ruby.c if_sniff.c \
150             gui_beval.c workshop.c wsdebug.c integration.c netbeans.c
151   
152 + # Unittest files
153 + MEMFILE_TEST_SRC = memfile_test.c
154 + MEMFILE_TEST_TARGET = memfile_test$(EXEEXT)
155
156 + UNITTEST_SRC = $(MEMFILE_TEST_SRC)
157 + UNITTEST_TARGETS = $(MEMFILE_TEST_TARGET)
158
159   # All sources, also the ones that are not configured
160 ! ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC)
161   
162   # Which files to check with lint.  Select one of these three lines.  ALL_SRC
163   # checks more, but may not work well for checking a GUI that wasn't configured.
164 ***************
165 *** 1492,1498 ****
166   #LINT_SRC = $(ALL_SRC)
167   #LINT_SRC = $(BASIC_SRC)
168   
169 ! OBJ = \
170         objects/buffer.o \
171         objects/blowfish.o \
172         objects/charset.o \
173 --- 1501,1507 ----
174   #LINT_SRC = $(ALL_SRC)
175   #LINT_SRC = $(BASIC_SRC)
176   
177 ! OBJ_COMMON = \
178         objects/buffer.o \
179         objects/blowfish.o \
180         objects/charset.o \
181 ***************
182 *** 1513,1522 ****
183         $(HANGULIN_OBJ) \
184         objects/if_cscope.o \
185         objects/if_xcmdsrv.o \
186 -       objects/main.o \
187         objects/mark.o \
188 !       objects/memfile.o \
189 !       objects/memline.o \
190         objects/menu.o \
191         objects/message.o \
192         objects/misc1.o \
193 --- 1522,1529 ----
194         $(HANGULIN_OBJ) \
195         objects/if_cscope.o \
196         objects/if_xcmdsrv.o \
197         objects/mark.o \
198 !         objects/memline.o \
199         objects/menu.o \
200         objects/message.o \
201         objects/misc1.o \
202 ***************
203 *** 1541,1546 ****
204 --- 1548,1554 ----
205         objects/term.o \
206         objects/ui.o \
207         objects/undo.o \
208 +       objects/version.o \
209         objects/window.o \
210         $(GUI_OBJ) \
211         $(LUA_OBJ) \
212 ***************
213 *** 1555,1560 ****
214 --- 1563,1575 ----
215         $(NETBEANS_OBJ) \
216         $(WSDEBUG_OBJ)
217   
218 + OBJ = $(OBJ_COMMON) \
219 +       objects/main.o \
220 +       objects/memfile.o \
221
222 + MEMFILE_TEST_OBJ = $(OBJ_COMMON) \
223 +         objects/memfile_test.o
224
225   PRO_AUTO = \
226         blowfish.pro \
227         buffer.pro \
228 ***************
229 *** 1700,1706 ****
230   $(VIMTARGET): auto/config.mk objects $(OBJ) version.c version.h
231         $(CCC) version.c -o objects/version.o
232         @LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
233 !               -o $(VIMTARGET) $(OBJ) objects/version.o $(ALL_LIBS)" \
234                 MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \
235                 sh $(srcdir)/link.sh
236   
237 --- 1715,1721 ----
238   $(VIMTARGET): auto/config.mk objects $(OBJ) version.c version.h
239         $(CCC) version.c -o objects/version.o
240         @LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
241 !               -o $(VIMTARGET) $(OBJ) $(ALL_LIBS)" \
242                 MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \
243                 sh $(srcdir)/link.sh
244   
245 ***************
246 *** 1825,1830 ****
247 --- 1840,1854 ----
248                 ln -s $(VIMTARGET) vim; \
249         fi
250         cd testdir; $(MAKE) -f Makefile $(GUI_TESTTARGET) VIMPROG=../$(VIMTARGET) $(GUI_TESTARG)
251 +       $(MAKE) -f Makefile unittest
252
253 + unittesttargets:
254 +       $(MAKE) -f Makefile $(UNITTEST_TARGETS)
255
256 + unittest unittests: $(UNITTEST_TARGETS)
257 +       @for t in $(UNITTEST_TARGETS); do \
258 +               ./$$t || exit 1; echo $$t passed; \
259 +       done
260   
261   testclean:
262         cd testdir; $(MAKE) -f Makefile clean
263 ***************
264 *** 1832,1837 ****
265 --- 1856,1872 ----
266                 cd $(PODIR); $(MAKE) checkclean; \
267         fi
268   
269 + # Unittests
270 + # It's build just like Vim to satisfy all dependencies.
271 + $(MEMFILE_TEST_TARGET): auto/config.mk objects $(MEMFILE_TEST_OBJ)
272 +       $(CCC) version.c -o objects/version.o
273 +       @LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
274 +               -o $(MEMFILE_TEST_TARGET) $(MEMFILE_TEST_OBJ) $(ALL_LIBS)" \
275 +               MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \
276 +               sh $(srcdir)/link.sh
277
278 + # install targets
279
280   install: $(GUI_INSTALL)
281   
282   install_normal: installvim installtools $(INSTALL_LANGS) install-icons
283 ***************
284 *** 2265,2270 ****
285 --- 2300,2306 ----
286         -rm -f *.o objects/* core $(VIMTARGET).core $(VIMTARGET) vim xxd/*.o
287         -rm -f $(TOOLS) auto/osdef.h auto/pathdef.c auto/if_perl.c
288         -rm -f conftest* *~ auto/link.sed
289 +       -rm -f $(UNITTEST_TARGETS)
290         -rm -f runtime pixmaps
291         -rm -rf $(APPDIR)
292         -rm -rf mzscheme_base.c
293 ***************
294 *** 2559,2564 ****
295 --- 2595,2603 ----
296   objects/memfile.o: memfile.c
297         $(CCC) -o $@ memfile.c
298   
299 + objects/memfile_test.o: memfile_test.c
300 +       $(CCC) -o $@ memfile_test.c
301
302   objects/memline.o: memline.c
303         $(CCC) -o $@ memline.c
304   
305 ***************
306 *** 2877,2883 ****
307   objects/os_unix.o: os_unix.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
308    ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
309    gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
310 !  arabic.h if_mzsch.h os_unixx.h
311   objects/pathdef.o: auto/pathdef.c vim.h auto/config.h feature.h os_unix.h \
312    auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
313    regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
314 --- 2916,2922 ----
315   objects/os_unix.o: os_unix.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
316    ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
317    gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
318 !  arabic.h os_unixx.h
319   objects/pathdef.o: auto/pathdef.c vim.h auto/config.h feature.h os_unix.h \
320    auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
321    regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
322 ***************
323 *** 3016,3021 ****
324 --- 3055,3064 ----
325   objects/pty.o: pty.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h \
326    keymap.h term.h macros.h option.h structs.h regexp.h gui.h gui_beval.h \
327    proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h arabic.h
328 + objects/memfile_test.o: memfile_test.c main.c vim.h auto/config.h feature.h \
329 +  os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h \
330 +  structs.h regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h \
331 +  proto.h globals.h farsi.h arabic.h farsi.c arabic.c memfile.c
332   objects/hangulin.o: hangulin.c vim.h auto/config.h feature.h os_unix.h \
333    auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
334    regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
335 ***************
336 *** 3027,3033 ****
337   objects/if_mzsch.o: if_mzsch.c vim.h auto/config.h feature.h os_unix.h \
338    auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
339    regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
340 !  globals.h farsi.h arabic.h if_mzsch.h mzscheme_base.c
341   objects/if_perl.o: auto/if_perl.c vim.h auto/config.h feature.h os_unix.h \
342    auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
343    regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
344 --- 3070,3076 ----
345   objects/if_mzsch.o: if_mzsch.c vim.h auto/config.h feature.h os_unix.h \
346    auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
347    regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
348 !  globals.h farsi.h arabic.h if_mzsch.h
349   objects/if_perl.o: auto/if_perl.c vim.h auto/config.h feature.h os_unix.h \
350    auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
351    regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
352 ***************
353 *** 3048,3054 ****
354    ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
355    gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
356    arabic.h
357 ! objects/if_ruby.o: if_ruby.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h \
358    ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
359    gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
360    arabic.h version.h
361 --- 3091,3097 ----
362    ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
363    gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
364    arabic.h
365 ! objects/if_ruby.o: if_ruby.c auto/config.h vim.h feature.h os_unix.h auto/osdef.h \
366    ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
367    gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
368    arabic.h version.h
369 *** ../vim-7.3.142/src/main.c   2011-02-15 16:29:54.000000000 +0100
370 --- src/main.c  2011-03-18 13:19:48.000000000 +0100
371 ***************
372 *** 92,128 ****
373   #define EDIT_TAG    3     /* tag name argument given, use tagname */
374   #define EDIT_QF           4       /* start in quickfix mode */
375   
376 ! #if defined(UNIX) || defined(VMS)
377   static int file_owned __ARGS((char *fname));
378   #endif
379   static void mainerr __ARGS((int, char_u *));
380   static void main_msg __ARGS((char *s));
381   static void usage __ARGS((void));
382   static int get_number_arg __ARGS((char_u *p, int *idx, int def));
383 ! #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
384   static void init_locale __ARGS((void));
385 ! #endif
386   static void parse_command_name __ARGS((mparm_T *parmp));
387   static void early_arg_scan __ARGS((mparm_T *parmp));
388   static void command_line_scan __ARGS((mparm_T *parmp));
389   static void check_tty __ARGS((mparm_T *parmp));
390   static void read_stdin __ARGS((void));
391   static void create_windows __ARGS((mparm_T *parmp));
392 ! #ifdef FEAT_WINDOWS
393   static void edit_buffers __ARGS((mparm_T *parmp));
394 ! #endif
395   static void exe_pre_commands __ARGS((mparm_T *parmp));
396   static void exe_commands __ARGS((mparm_T *parmp));
397   static void source_startup_scripts __ARGS((mparm_T *parmp));
398   static void main_start_gui __ARGS((void));
399 ! #if defined(HAS_SWAP_EXISTS_ACTION)
400   static void check_swap_exists_action __ARGS((void));
401 ! #endif
402 ! #ifdef FEAT_CLIENTSERVER
403   static void exec_on_server __ARGS((mparm_T *parmp));
404   static void prepare_server __ARGS((mparm_T *parmp));
405   static void cmdsrv_main __ARGS((int *argc, char **argv, char_u *serverName_arg, char_u **serverStr));
406   static char_u *serverMakeName __ARGS((char_u *arg, char *cmd));
407   #endif
408   
409   
410 --- 92,130 ----
411   #define EDIT_TAG    3     /* tag name argument given, use tagname */
412   #define EDIT_QF           4       /* start in quickfix mode */
413   
414 ! #if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN)
415   static int file_owned __ARGS((char *fname));
416   #endif
417   static void mainerr __ARGS((int, char_u *));
418 + #ifndef NO_VIM_MAIN
419   static void main_msg __ARGS((char *s));
420   static void usage __ARGS((void));
421   static int get_number_arg __ARGS((char_u *p, int *idx, int def));
422 ! # if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
423   static void init_locale __ARGS((void));
424 ! # endif
425   static void parse_command_name __ARGS((mparm_T *parmp));
426   static void early_arg_scan __ARGS((mparm_T *parmp));
427   static void command_line_scan __ARGS((mparm_T *parmp));
428   static void check_tty __ARGS((mparm_T *parmp));
429   static void read_stdin __ARGS((void));
430   static void create_windows __ARGS((mparm_T *parmp));
431 ! # ifdef FEAT_WINDOWS
432   static void edit_buffers __ARGS((mparm_T *parmp));
433 ! # endif
434   static void exe_pre_commands __ARGS((mparm_T *parmp));
435   static void exe_commands __ARGS((mparm_T *parmp));
436   static void source_startup_scripts __ARGS((mparm_T *parmp));
437   static void main_start_gui __ARGS((void));
438 ! # if defined(HAS_SWAP_EXISTS_ACTION)
439   static void check_swap_exists_action __ARGS((void));
440 ! # endif
441 ! # if defined(FEAT_CLIENTSERVER) || defined(PROTO)
442   static void exec_on_server __ARGS((mparm_T *parmp));
443   static void prepare_server __ARGS((mparm_T *parmp));
444   static void cmdsrv_main __ARGS((int *argc, char **argv, char_u *serverName_arg, char_u **serverStr));
445   static char_u *serverMakeName __ARGS((char_u *arg, char *cmd));
446 + # endif
447   #endif
448   
449   
450 ***************
451 *** 145,151 ****
452   #define ME_INVALID_ARG                5
453   };
454   
455 ! #ifndef PROTO     /* don't want a prototype for main() */
456       int
457   # ifdef VIMDLL
458   _export
459 --- 147,154 ----
460   #define ME_INVALID_ARG                5
461   };
462   
463 ! #ifndef NO_VIM_MAIN   /* skip this for unittests */
464 ! #ifndef PROTO         /* don't want a prototype for main() */
465       int
466   # ifdef VIMDLL
467   _export
468 ***************
469 *** 966,971 ****
470 --- 969,975 ----
471       return 0;
472   }
473   #endif /* PROTO */
474 + #endif /* NO_VIM_MAIN */
475   
476   /*
477    * Main loop: Execute Normal mode commands until exiting Vim.
478 ***************
479 *** 1430,1435 ****
480 --- 1434,1440 ----
481       mch_exit(exitval);
482   }
483   
484 + #ifndef NO_VIM_MAIN
485   /*
486    * Get a (optional) count for a Vim argument.
487    */
488 ***************
489 *** 2994,2999 ****
490 --- 2999,3006 ----
491   #endif
492   }
493   
494 + #endif  /* NO_VIM_MAIN */
495
496   /*
497    * Get an environment variable, and execute it as Ex commands.
498    * Returns FAIL if the environment variable was not executed, OK otherwise.
499 ***************
500 *** 3033,3039 ****
501       return FAIL;
502   }
503   
504 ! #if defined(UNIX) || defined(VMS)
505   /*
506    * Return TRUE if we are certain the user owns the file "fname".
507    * Used for ".vimrc" and ".exrc".
508 --- 3040,3046 ----
509       return FAIL;
510   }
511   
512 ! #if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN)
513   /*
514    * Return TRUE if we are certain the user owns the file "fname".
515    * Used for ".vimrc" and ".exrc".
516 ***************
517 *** 3091,3096 ****
518 --- 3098,3104 ----
519       mainerr(ME_ARG_MISSING, str);
520   }
521   
522 + #ifndef NO_VIM_MAIN
523   /*
524    * print a message with three spaces prepended and '\n' appended.
525    */
526 ***************
527 *** 3311,3316 ****
528 --- 3319,3326 ----
529   }
530   #endif
531   
532 + #endif
533
534   #if defined(STARTUPTIME) || defined(PROTO)
535   static void time_diff __ARGS((struct timeval *then, struct timeval *now));
536   
537 ***************
538 *** 3420,3426 ****
539   
540   #endif
541   
542 ! #if defined(FEAT_CLIENTSERVER) || defined(PROTO)
543   
544   /*
545    * Common code for the X command server and the Win32 command server.
546 --- 3430,3436 ----
547   
548   #endif
549   
550 ! #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO)
551   
552   /*
553    * Common code for the X command server and the Win32 command server.
554 ***************
555 *** 3888,3893 ****
556 --- 3898,3929 ----
557   }
558   
559   /*
560 +  * Make our basic server name: use the specified "arg" if given, otherwise use
561 +  * the tail of the command "cmd" we were started with.
562 +  * Return the name in allocated memory.  This doesn't include a serial number.
563 +  */
564 +     static char_u *
565 + serverMakeName(arg, cmd)
566 +     char_u    *arg;
567 +     char      *cmd;
568 + {
569 +     char_u *p;
570
571 +     if (arg != NULL && *arg != NUL)
572 +       p = vim_strsave_up(arg);
573 +     else
574 +     {
575 +       p = vim_strsave_up(gettail((char_u *)cmd));
576 +       /* Remove .exe or .bat from the name. */
577 +       if (p != NULL && vim_strchr(p, '.') != NULL)
578 +           *vim_strchr(p, '.') = NUL;
579 +     }
580 +     return p;
581 + }
582 + #endif /* FEAT_CLIENTSERVER */
583
584 + #if defined(FEAT_CLIENTSERVER) || defined(PROTO)
585 + /*
586    * Replace termcodes such as <CR> and insert as key presses if there is room.
587    */
588       void
589 ***************
590 *** 3998,4029 ****
591   # endif
592       return res;
593   }
594
595
596 ! /*
597 !  * Make our basic server name: use the specified "arg" if given, otherwise use
598 !  * the tail of the command "cmd" we were started with.
599 !  * Return the name in allocated memory.  This doesn't include a serial number.
600 !  */
601 !     static char_u *
602 ! serverMakeName(arg, cmd)
603 !     char_u    *arg;
604 !     char      *cmd;
605 ! {
606 !     char_u *p;
607
608 !     if (arg != NULL && *arg != NUL)
609 !       p = vim_strsave_up(arg);
610 !     else
611 !     {
612 !       p = vim_strsave_up(gettail((char_u *)cmd));
613 !       /* Remove .exe or .bat from the name. */
614 !       if (p != NULL && vim_strchr(p, '.') != NULL)
615 !           *vim_strchr(p, '.') = NUL;
616 !     }
617 !     return p;
618 ! }
619 ! #endif /* FEAT_CLIENTSERVER */
620   
621   /*
622    * When FEAT_FKMAP is defined, also compile the Farsi source code.
623 --- 4034,4040 ----
624   # endif
625       return res;
626   }
627 ! #endif
628   
629   /*
630    * When FEAT_FKMAP is defined, also compile the Farsi source code.
631 *** ../vim-7.3.142/src/memfile.c        2010-12-17 18:06:00.000000000 +0100
632 --- src/memfile.c       2011-03-03 18:47:39.000000000 +0100
633 ***************
634 *** 84,89 ****
635 --- 84,96 ----
636   static int  mf_write_block __ARGS((memfile_T *mfp, bhdr_T *hp, off_t offset, unsigned size));
637   static int  mf_trans_add __ARGS((memfile_T *, bhdr_T *));
638   static void mf_do_open __ARGS((memfile_T *, char_u *, int));
639 + static void mf_hash_init __ARGS((mf_hashtab_T *));
640 + static void mf_hash_free __ARGS((mf_hashtab_T *));
641 + static void mf_hash_free_all __ARGS((mf_hashtab_T *));
642 + static mf_hashitem_T *mf_hash_find __ARGS((mf_hashtab_T *, blocknr_T));
643 + static void mf_hash_add_item __ARGS((mf_hashtab_T *, mf_hashitem_T *));
644 + static void mf_hash_rem_item __ARGS((mf_hashtab_T *, mf_hashitem_T *));
645 + static int mf_hash_grow __ARGS((mf_hashtab_T *));
646   
647   /*
648    * The functions for using a memfile:
649 ***************
650 *** 119,125 ****
651       int               flags;
652   {
653       memfile_T         *mfp;
654 -     int                       i;
655       off_t             size;
656   #if defined(STATFS) && defined(UNIX) && !defined(__QNX__)
657   # define USE_FSTATFS
658 --- 126,131 ----
659 ***************
660 *** 152,162 ****
661       mfp->mf_used_last = NULL;
662       mfp->mf_dirty = FALSE;
663       mfp->mf_used_count = 0;
664 !     for (i = 0; i < MEMHASHSIZE; ++i)
665 !     {
666 !       mfp->mf_hash[i] = NULL;         /* hash lists are empty */
667 !       mfp->mf_trans[i] = NULL;        /* trans lists are empty */
668 !     }
669       mfp->mf_page_size = MEMFILE_PAGE_SIZE;
670   #ifdef FEAT_CRYPT
671       mfp->mf_old_key = NULL;
672 --- 158,165 ----
673       mfp->mf_used_last = NULL;
674       mfp->mf_dirty = FALSE;
675       mfp->mf_used_count = 0;
676 !     mf_hash_init(&mfp->mf_hash);
677 !     mf_hash_init(&mfp->mf_trans);
678       mfp->mf_page_size = MEMFILE_PAGE_SIZE;
679   #ifdef FEAT_CRYPT
680       mfp->mf_old_key = NULL;
681 ***************
682 *** 242,249 ****
683       int               del_file;
684   {
685       bhdr_T    *hp, *nextp;
686 -     NR_TRANS  *tp, *tpnext;
687 -     int               i;
688   
689       if (mfp == NULL)              /* safety check */
690         return;
691 --- 245,250 ----
692 ***************
693 *** 263,274 ****
694       }
695       while (mfp->mf_free_first != NULL)            /* free entries in free list */
696         vim_free(mf_rem_free(mfp));
697 !     for (i = 0; i < MEMHASHSIZE; ++i)     /* free entries in trans lists */
698 !       for (tp = mfp->mf_trans[i]; tp != NULL; tp = tpnext)
699 !       {
700 !           tpnext = tp->nt_next;
701 !           vim_free(tp);
702 !       }
703       vim_free(mfp->mf_fname);
704       vim_free(mfp->mf_ffname);
705       vim_free(mfp);
706 --- 264,271 ----
707       }
708       while (mfp->mf_free_first != NULL)            /* free entries in free list */
709         vim_free(mf_rem_free(mfp));
710 !     mf_hash_free(&mfp->mf_hash);
711 !     mf_hash_free_all(&mfp->mf_trans);     /* free hashtable and its items */
712       vim_free(mfp->mf_fname);
713       vim_free(mfp->mf_ffname);
714       vim_free(mfp);
715 ***************
716 *** 743,758 ****
717       memfile_T *mfp;
718       bhdr_T    *hp;
719   {
720 !     bhdr_T    *hhp;
721 !     int               hash;
722
723 !     hash = MEMHASH(hp->bh_bnum);
724 !     hhp = mfp->mf_hash[hash];
725 !     hp->bh_hash_next = hhp;
726 !     hp->bh_hash_prev = NULL;
727 !     if (hhp != NULL)
728 !       hhp->bh_hash_prev = hp;
729 !     mfp->mf_hash[hash] = hp;
730   }
731   
732   /*
733 --- 740,746 ----
734       memfile_T *mfp;
735       bhdr_T    *hp;
736   {
737 !     mf_hash_add_item(&mfp->mf_hash, (mf_hashitem_T *)hp);
738   }
739   
740   /*
741 ***************
742 *** 763,775 ****
743       memfile_T *mfp;
744       bhdr_T    *hp;
745   {
746 !     if (hp->bh_hash_prev == NULL)
747 !       mfp->mf_hash[MEMHASH(hp->bh_bnum)] = hp->bh_hash_next;
748 !     else
749 !       hp->bh_hash_prev->bh_hash_next = hp->bh_hash_next;
750
751 !     if (hp->bh_hash_next)
752 !       hp->bh_hash_next->bh_hash_prev = hp->bh_hash_prev;
753   }
754   
755   /*
756 --- 751,757 ----
757       memfile_T *mfp;
758       bhdr_T    *hp;
759   {
760 !     mf_hash_rem_item(&mfp->mf_hash, (mf_hashitem_T *)hp);
761   }
762   
763   /*
764 ***************
765 *** 780,791 ****
766       memfile_T *mfp;
767       blocknr_T nr;
768   {
769 !     bhdr_T    *hp;
770
771 !     for (hp = mfp->mf_hash[MEMHASH(nr)]; hp != NULL; hp = hp->bh_hash_next)
772 !       if (hp->bh_bnum == nr)
773 !           break;
774 !     return hp;
775   }
776   
777   /*
778 --- 762,768 ----
779       memfile_T *mfp;
780       blocknr_T nr;
781   {
782 !     return (bhdr_T *)mf_hash_find(&mfp->mf_hash, nr);
783   }
784   
785   /*
786 ***************
787 *** 1187,1193 ****
788   {
789       bhdr_T    *freep;
790       blocknr_T new_bnum;
791 -     int               hash;
792       NR_TRANS  *np;
793       int               page_count;
794   
795 --- 1164,1169 ----
796 ***************
797 *** 1235,1246 ****
798       hp->bh_bnum = new_bnum;
799       mf_ins_hash(mfp, hp);                 /* insert in new hash list */
800   
801 !     hash = MEMHASH(np->nt_old_bnum);      /* insert in trans list */
802 !     np->nt_next = mfp->mf_trans[hash];
803 !     mfp->mf_trans[hash] = np;
804 !     if (np->nt_next != NULL)
805 !       np->nt_next->nt_prev = np;
806 !     np->nt_prev = NULL;
807   
808       return OK;
809   }
810 --- 1211,1218 ----
811       hp->bh_bnum = new_bnum;
812       mf_ins_hash(mfp, hp);                 /* insert in new hash list */
813   
814 !     /* Insert "np" into "mf_trans" hashtable with key "np->nt_old_bnum" */
815 !     mf_hash_add_item(&mfp->mf_trans, (mf_hashitem_T *)np);
816   
817       return OK;
818   }
819 ***************
820 *** 1255,1279 ****
821       memfile_T *mfp;
822       blocknr_T old_nr;
823   {
824 -     int               hash;
825       NR_TRANS  *np;
826       blocknr_T new_bnum;
827   
828 !     hash = MEMHASH(old_nr);
829 !     for (np = mfp->mf_trans[hash]; np != NULL; np = np->nt_next)
830 !       if (np->nt_old_bnum == old_nr)
831 !           break;
832       if (np == NULL)           /* not found */
833         return old_nr;
834   
835       mfp->mf_neg_count--;
836       new_bnum = np->nt_new_bnum;
837 !     if (np->nt_prev != NULL)          /* remove entry from the trans list */
838 !       np->nt_prev->nt_next = np->nt_next;
839 !     else
840 !       mfp->mf_trans[hash] = np->nt_next;
841 !     if (np->nt_next != NULL)
842 !       np->nt_next->nt_prev = np->nt_prev;
843       vim_free(np);
844   
845       return new_bnum;
846 --- 1227,1246 ----
847       memfile_T *mfp;
848       blocknr_T old_nr;
849   {
850       NR_TRANS  *np;
851       blocknr_T new_bnum;
852   
853 !     np = (NR_TRANS *)mf_hash_find(&mfp->mf_trans, old_nr);
854
855       if (np == NULL)           /* not found */
856         return old_nr;
857   
858       mfp->mf_neg_count--;
859       new_bnum = np->nt_new_bnum;
860
861 !     /* remove entry from the trans list */
862 !     mf_hash_rem_item(&mfp->mf_trans, (mf_hashitem_T *)np);
863
864       vim_free(np);
865   
866       return new_bnum;
867 ***************
868 *** 1397,1399 ****
869 --- 1364,1570 ----
870         mch_hide(mfp->mf_fname);    /* try setting the 'hidden' flag */
871       }
872   }
873
874 + /*
875 +  * Implementation of mf_hashtab_T follows.
876 +  */
877
878 + /*
879 +  * The number of buckets in the hashtable is increased by a factor of
880 +  * MHT_GROWTH_FACTOR when the average number of items per bucket
881 +  * exceeds 2 ^ MHT_LOG_LOAD_FACTOR.
882 +  */
883 + #define MHT_LOG_LOAD_FACTOR 6
884 + #define MHT_GROWTH_FACTOR   2   /* must be a power of two */
885
886 + /*
887 +  * Initialize an empty hash table.
888 +  */
889 +     static void
890 + mf_hash_init(mht)
891 +     mf_hashtab_T *mht;
892 + {
893 +     vim_memset(mht, 0, sizeof(mf_hashtab_T));
894 +     mht->mht_buckets = mht->mht_small_buckets;
895 +     mht->mht_mask = MHT_INIT_SIZE - 1;
896 + }
897
898 + /*
899 +  * Free the array of a hash table.  Does not free the items it contains!
900 +  * The hash table must not be used again without another mf_hash_init() call.
901 +  */
902 +     static void
903 + mf_hash_free(mht)
904 +     mf_hashtab_T *mht;
905 + {
906 +     if (mht->mht_buckets != mht->mht_small_buckets)
907 +       vim_free(mht->mht_buckets);
908 + }
909
910 + /*
911 +  * Free the array of a hash table and all the items it contains.
912 +  */
913 +     static void
914 + mf_hash_free_all(mht)
915 +     mf_hashtab_T    *mht;
916 + {
917 +     long_u        idx;
918 +     mf_hashitem_T   *mhi;
919 +     mf_hashitem_T   *next;
920
921 +     for (idx = 0; idx <= mht->mht_mask; idx++)
922 +       for (mhi = mht->mht_buckets[idx]; mhi != NULL; mhi = next)
923 +       {
924 +           next = mhi->mhi_next;
925 +           vim_free(mhi);
926 +       }
927
928 +     mf_hash_free(mht);
929 + }
930
931 + /*
932 +  * Find "key" in hashtable "mht".
933 +  * Returns a pointer to a mf_hashitem_T or NULL if the item was not found.
934 +  */
935 +     static mf_hashitem_T *
936 + mf_hash_find(mht, key)
937 +     mf_hashtab_T    *mht;
938 +     blocknr_T     key;
939 + {
940 +     mf_hashitem_T   *mhi;
941
942 +     mhi = mht->mht_buckets[key & mht->mht_mask];
943 +     while (mhi != NULL && mhi->mhi_key != key)
944 +       mhi = mhi->mhi_next;
945
946 +     return mhi;
947 + }
948
949 + /*
950 +  * Add item "mhi" to hashtable "mht".
951 +  * "mhi" must not be NULL.
952 +  */
953 +     static void
954 + mf_hash_add_item(mht, mhi)
955 +     mf_hashtab_T    *mht;
956 +     mf_hashitem_T   *mhi;
957 + {
958 +     long_u        idx;
959
960 +     idx = mhi->mhi_key & mht->mht_mask;
961 +     mhi->mhi_next = mht->mht_buckets[idx];
962 +     mhi->mhi_prev = NULL;
963 +     if (mhi->mhi_next != NULL)
964 +       mhi->mhi_next->mhi_prev = mhi;
965 +     mht->mht_buckets[idx] = mhi;
966
967 +     mht->mht_count++;
968
969 +     /*
970 +      * Grow hashtable when we have more thank 2^MHT_LOG_LOAD_FACTOR
971 +      * items per bucket on average
972 +      */
973 +     if (mht->mht_fixed == 0
974 +       && (mht->mht_count >> MHT_LOG_LOAD_FACTOR) > mht->mht_mask)
975 +     {
976 +       if (mf_hash_grow(mht) == FAIL)
977 +       {
978 +           /* stop trying to grow after first failure to allocate memory */
979 +           mht->mht_fixed = 1;
980 +       }
981 +     }
982 + }
983
984 + /*
985 +  * Remove item "mhi" from hashtable "mht".
986 +  * "mhi" must not be NULL and must have been inserted into "mht".
987 +  */
988 +     static void
989 + mf_hash_rem_item(mht, mhi)
990 +     mf_hashtab_T    *mht;
991 +     mf_hashitem_T   *mhi;
992 + {
993 +     if (mhi->mhi_prev == NULL)
994 +       mht->mht_buckets[mhi->mhi_key & mht->mht_mask] = mhi->mhi_next;
995 +     else
996 +       mhi->mhi_prev->mhi_next = mhi->mhi_next;
997
998 +     if (mhi->mhi_next != NULL)
999 +       mhi->mhi_next->mhi_prev = mhi->mhi_prev;
1000
1001 +     mht->mht_count--;
1002
1003 +     /* We could shrink the table here, but it typically takes little memory,
1004 +      * so why bother?  */
1005 + }
1006
1007 + /*
1008 +  * Increase number of buckets in the hashtable by MHT_GROWTH_FACTOR and
1009 +  * rehash items.
1010 +  * Returns FAIL when out of memory.
1011 +  */
1012 +     static int
1013 + mf_hash_grow(mht)
1014 +     mf_hashtab_T    *mht;
1015 + {
1016 +     long_u        i, j;
1017 +     int                   shift;
1018 +     mf_hashitem_T   *mhi;
1019 +     mf_hashitem_T   *tails[MHT_GROWTH_FACTOR];
1020 +     mf_hashitem_T   **buckets;
1021 +     size_t        size;
1022
1023 +     size = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR * sizeof(void *);
1024 +     buckets = (mf_hashitem_T **)lalloc_clear(size, FALSE);
1025 +     if (buckets == NULL)
1026 +       return FAIL;
1027
1028 +     shift = 0;
1029 +     while ((mht->mht_mask >> shift) != 0)
1030 +       shift++;
1031
1032 +     for (i = 0; i <= mht->mht_mask; i++)
1033 +     {
1034 +       /*
1035 +        * Traverse the items in the i-th original bucket and move them into
1036 +        * MHT_GROWTH_FACTOR new buckets, preserving their relative order
1037 +        * within each new bucket.  Preserving the order is important because
1038 +        * mf_get() tries to keep most recently used items at the front of
1039 +        * each bucket.
1040 +        *
1041 +        * Here we strongly rely on the fact the hashes are computed modulo
1042 +        * a power of two.
1043 +        */
1044
1045 +       vim_memset(tails, 0, sizeof(tails));
1046
1047 +       for (mhi = mht->mht_buckets[i]; mhi != NULL; mhi = mhi->mhi_next)
1048 +       {
1049 +           j = (mhi->mhi_key >> shift) & (MHT_GROWTH_FACTOR - 1);
1050 +           if (tails[j] == NULL)
1051 +           {
1052 +               buckets[i + (j << shift)] = mhi;
1053 +               tails[j] = mhi;
1054 +               mhi->mhi_prev = NULL;
1055 +           }
1056 +           else
1057 +           {
1058 +               tails[j]->mhi_next = mhi;
1059 +               mhi->mhi_prev = tails[j];
1060 +               tails[j] = mhi;
1061 +           }
1062 +       }
1063
1064 +       for (j = 0; j < MHT_GROWTH_FACTOR; j++)
1065 +           if (tails[j] != NULL)
1066 +               tails[j]->mhi_next = NULL;
1067 +     }
1068
1069 +     if (mht->mht_buckets != mht->mht_small_buckets)
1070 +       vim_free(mht->mht_buckets);
1071
1072 +     mht->mht_buckets = buckets;
1073 +     mht->mht_mask = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR - 1;
1074
1075 +     return OK;
1076 + }
1077 *** ../vim-7.3.142/src/memfile_test.c   2011-03-03 21:58:14.000000000 +0100
1078 --- src/memfile_test.c  2011-03-03 20:40:29.000000000 +0100
1079 ***************
1080 *** 0 ****
1081 --- 1,145 ----
1082 + /* vi:set ts=8 sts=4 sw=4:
1083 +  *
1084 +  * VIM - Vi IMproved  by Bram Moolenaar
1085 +  *
1086 +  * Do ":help uganda"  in Vim to read copying and usage conditions.
1087 +  * Do ":help credits" in Vim to see a list of people who contributed.
1088 +  * See README.txt for an overview of the Vim source code.
1089 +  */
1090
1091 + /*
1092 +  * memfile_test.c: Unittests for memfile.c
1093 +  * Mostly by Ivan Krasilnikov.
1094 +  */
1095
1096 + #undef NDEBUG
1097 + #include <assert.h>
1098
1099 + /* Must include main.c because it contains much more than just main() */
1100 + #define NO_VIM_MAIN
1101 + #include "main.c"
1102
1103 + /* This file has to be included because the tested functions are static */
1104 + #include "memfile.c"
1105
1106 + #define index_to_key(i) ((i) ^ 15167)
1107 + #define TEST_COUNT 50000
1108
1109 + static void test_mf_hash __ARGS((void));
1110
1111 + /*
1112 +  * Test mf_hash_*() functions.
1113 +  */
1114 +     static void
1115 + test_mf_hash()
1116 + {
1117 +     mf_hashtab_T   ht;
1118 +     mf_hashitem_T  *item;
1119 +     blocknr_T      key;
1120 +     long_u       i;
1121 +     long_u       num_buckets;
1122
1123 +     mf_hash_init(&ht);
1124
1125 +     /* insert some items and check invariants */
1126 +     for (i = 0; i < TEST_COUNT; i++)
1127 +     {
1128 +       assert(ht.mht_count == i);
1129
1130 +       /* check that number of buckets is a power of 2 */
1131 +       num_buckets = ht.mht_mask + 1;
1132 +       assert(num_buckets > 0 && (num_buckets & (num_buckets - 1)) == 0);
1133
1134 +       /* check load factor */
1135 +       assert(ht.mht_count <= (num_buckets << MHT_LOG_LOAD_FACTOR));
1136
1137 +       if (i < (MHT_INIT_SIZE << MHT_LOG_LOAD_FACTOR))
1138 +       {
1139 +           /* first expansion shouldn't have occurred yet */
1140 +           assert(num_buckets == MHT_INIT_SIZE);
1141 +           assert(ht.mht_buckets == ht.mht_small_buckets);
1142 +       }
1143 +       else
1144 +       {
1145 +           assert(num_buckets > MHT_INIT_SIZE);
1146 +           assert(ht.mht_buckets != ht.mht_small_buckets);
1147 +       }
1148
1149 +       key = index_to_key(i);
1150 +       assert(mf_hash_find(&ht, key) == NULL);
1151
1152 +       /* allocate and add new item */
1153 +       item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);
1154 +       assert(item != NULL);
1155 +       item->mhi_key = key;
1156 +       mf_hash_add_item(&ht, item);
1157
1158 +       assert(mf_hash_find(&ht, key) == item);
1159
1160 +       if (ht.mht_mask + 1 != num_buckets)
1161 +       {
1162 +           /* hash table was expanded */
1163 +           assert(ht.mht_mask + 1 == num_buckets * MHT_GROWTH_FACTOR);
1164 +           assert(i + 1 == (num_buckets << MHT_LOG_LOAD_FACTOR));
1165 +       }
1166 +     }
1167
1168 +     /* check presence of inserted items */
1169 +     for (i = 0; i < TEST_COUNT; i++)
1170 +     {
1171 +       key = index_to_key(i);
1172 +       item = mf_hash_find(&ht, key);
1173 +       assert(item != NULL);
1174 +       assert(item->mhi_key == key);
1175 +     }
1176
1177 +     /* delete some items */
1178 +     for (i = 0; i < TEST_COUNT; i++)
1179 +     {
1180 +       if (i % 100 < 70)
1181 +       {
1182 +           key = index_to_key(i);
1183 +           item = mf_hash_find(&ht, key);
1184 +           assert(item != NULL);
1185 +           assert(item->mhi_key == key);
1186
1187 +           mf_hash_rem_item(&ht, item);
1188 +           assert(mf_hash_find(&ht, key) == NULL);
1189
1190 +           mf_hash_add_item(&ht, item);
1191 +           assert(mf_hash_find(&ht, key) == item);
1192
1193 +           mf_hash_rem_item(&ht, item);
1194 +           assert(mf_hash_find(&ht, key) == NULL);
1195
1196 +           vim_free(item);
1197 +       }
1198 +     }
1199
1200 +     /* check again */
1201 +     for (i = 0; i < TEST_COUNT; i++)
1202 +     {
1203 +       key = index_to_key(i);
1204 +       item = mf_hash_find(&ht, key);
1205
1206 +       if (i % 100 < 70)
1207 +       {
1208 +           assert(item == NULL);
1209 +       }
1210 +       else
1211 +       {
1212 +           assert(item != NULL);
1213 +           assert(item->mhi_key == key);
1214 +       }
1215 +     }
1216
1217 +     /* free hash table and all remaining items */
1218 +     mf_hash_free_all(&ht);
1219 + }
1220
1221 +     int
1222 + main()
1223 + {
1224 +     test_mf_hash();
1225 +     return 0;
1226 + }
1227 *** ../vim-7.3.142/src/structs.h        2011-02-15 17:39:14.000000000 +0100
1228 --- src/structs.h       2011-03-03 18:49:01.000000000 +0100
1229 ***************
1230 *** 378,383 ****
1231 --- 378,412 ----
1232   typedef long              blocknr_T;
1233   
1234   /*
1235 +  * mf_hashtab_T is a chained hashtable with blocknr_T key and arbitrary
1236 +  * structures as items.  This is an intrusive data structure: we require
1237 +  * that items begin with mf_hashitem_T which contains the key and linked
1238 +  * list pointers.  List of items in each bucket is doubly-linked.
1239 +  */
1240
1241 + typedef struct mf_hashitem_S mf_hashitem_T;
1242
1243 + struct mf_hashitem_S
1244 + {
1245 +     mf_hashitem_T   *mhi_next;
1246 +     mf_hashitem_T   *mhi_prev;
1247 +     blocknr_T     mhi_key;
1248 + };
1249
1250 + #define MHT_INIT_SIZE   64
1251
1252 + typedef struct mf_hashtab_S
1253 + {
1254 +     long_u        mht_mask;       /* mask used for hash value (nr of items
1255 +                                    * in array is "mht_mask" + 1) */
1256 +     long_u        mht_count;      /* nr of items inserted into hashtable */
1257 +     mf_hashitem_T   **mht_buckets;  /* points to mht_small_buckets or
1258 +                                    *dynamically allocated array */
1259 +     mf_hashitem_T   *mht_small_buckets[MHT_INIT_SIZE];   /* initial buckets */
1260 +     char          mht_fixed;      /* non-zero value forbids growth */
1261 + } mf_hashtab_T;
1262
1263 + /*
1264    * for each (previously) used block in the memfile there is one block header.
1265    *
1266    * The block may be linked in the used list OR in the free list.
1267 ***************
1268 *** 394,404 ****
1269   
1270   struct block_hdr
1271   {
1272       bhdr_T    *bh_next;           /* next block_hdr in free or used list */
1273       bhdr_T    *bh_prev;           /* previous block_hdr in used list */
1274 -     bhdr_T    *bh_hash_next;      /* next block_hdr in hash list */
1275 -     bhdr_T    *bh_hash_prev;      /* previous block_hdr in hash list */
1276 -     blocknr_T bh_bnum;            /* block number */
1277       char_u    *bh_data;           /* pointer to memory (for used block) */
1278       int               bh_page_count;      /* number of pages in this block */
1279   
1280 --- 423,433 ----
1281   
1282   struct block_hdr
1283   {
1284 +     mf_hashitem_T bh_hashitem;      /* header for hash table and key */
1285 + #define bh_bnum bh_hashitem.mhi_key /* block number, part of bh_hashitem */
1286
1287       bhdr_T    *bh_next;           /* next block_hdr in free or used list */
1288       bhdr_T    *bh_prev;           /* previous block_hdr in used list */
1289       char_u    *bh_data;           /* pointer to memory (for used block) */
1290       int               bh_page_count;      /* number of pages in this block */
1291   
1292 ***************
1293 *** 417,425 ****
1294   
1295   struct nr_trans
1296   {
1297 !     NR_TRANS  *nt_next;               /* next nr_trans in hash list */
1298 !     NR_TRANS  *nt_prev;               /* previous nr_trans in hash list */
1299 !     blocknr_T nt_old_bnum;            /* old, negative, number */
1300       blocknr_T nt_new_bnum;            /* new, positive, number */
1301   };
1302   
1303 --- 446,454 ----
1304   
1305   struct nr_trans
1306   {
1307 !     mf_hashitem_T nt_hashitem;                /* header for hash table and key */
1308 ! #define nt_old_bnum nt_hashitem.mhi_key       /* old, negative, number */
1309
1310       blocknr_T nt_new_bnum;            /* new, positive, number */
1311   };
1312   
1313 ***************
1314 *** 499,510 ****
1315   
1316   typedef struct file_buffer buf_T;  /* forward declaration */
1317   
1318 - /*
1319 -  * Simplistic hashing scheme to quickly locate the blocks in the used list.
1320 -  * 64 blocks are found directly (64 * 4K = 256K, most files are smaller).
1321 -  */
1322 - #define MEMHASHSIZE   64
1323 - #define MEMHASH(nr)   ((nr) & (MEMHASHSIZE - 1))
1324   #define MF_SEED_LEN   8
1325   
1326   struct memfile
1327 --- 528,533 ----
1328 ***************
1329 *** 517,524 ****
1330       bhdr_T    *mf_used_last;          /* lru block_hdr in used list */
1331       unsigned  mf_used_count;          /* number of pages in used list */
1332       unsigned  mf_used_count_max;      /* maximum number of pages in memory */
1333 !     bhdr_T    *mf_hash[MEMHASHSIZE];  /* array of hash lists */
1334 !     NR_TRANS  *mf_trans[MEMHASHSIZE]; /* array of trans lists */
1335       blocknr_T mf_blocknr_max;         /* highest positive block number + 1*/
1336       blocknr_T mf_blocknr_min;         /* lowest negative block number - 1 */
1337       blocknr_T mf_neg_count;           /* number of negative blocks numbers */
1338 --- 540,547 ----
1339       bhdr_T    *mf_used_last;          /* lru block_hdr in used list */
1340       unsigned  mf_used_count;          /* number of pages in used list */
1341       unsigned  mf_used_count_max;      /* maximum number of pages in memory */
1342 !     mf_hashtab_T mf_hash;             /* hash lists */
1343 !     mf_hashtab_T mf_trans;            /* trans lists */
1344       blocknr_T mf_blocknr_max;         /* highest positive block number + 1*/
1345       blocknr_T mf_blocknr_min;         /* lowest negative block number - 1 */
1346       blocknr_T mf_neg_count;           /* number of negative blocks numbers */
1347 *** ../vim-7.3.142/src/testdir/Make_amiga.mak   2010-11-10 16:54:16.000000000 +0100
1348 --- src/testdir/Make_amiga.mak  2011-03-03 17:04:14.000000000 +0100
1349 ***************
1350 *** 28,34 ****
1351                 test61.out test62.out test63.out test64.out test65.out \
1352                 test66.out test67.out test68.out test69.out test70.out \
1353                 test71.out test72.out test73.out test74.out test75.out \
1354 !               test76.out
1355   
1356   .SUFFIXES: .in .out
1357   
1358 --- 28,34 ----
1359                 test61.out test62.out test63.out test64.out test65.out \
1360                 test66.out test67.out test68.out test69.out test70.out \
1361                 test71.out test72.out test73.out test74.out test75.out \
1362 !               test76.out test77.out
1363   
1364   .SUFFIXES: .in .out
1365   
1366 ***************
1367 *** 124,126 ****
1368 --- 124,127 ----
1369   test74.out: test74.in
1370   test75.out: test75.in
1371   test76.out: test76.in
1372 + test77.out: test77.in
1373 *** ../vim-7.3.142/src/testdir/Make_dos.mak     2010-11-10 16:54:16.000000000 +0100
1374 --- src/testdir/Make_dos.mak    2011-03-03 17:04:20.000000000 +0100
1375 ***************
1376 *** 28,34 ****
1377                 test37.out test38.out test39.out test40.out test41.out \
1378                 test42.out test52.out test65.out test66.out test67.out \
1379                 test68.out test69.out test71.out test72.out test73.out \
1380 !               test74.out test75.out test76.out
1381   
1382   SCRIPTS32 =   test50.out test70.out
1383   
1384 --- 28,34 ----
1385                 test37.out test38.out test39.out test40.out test41.out \
1386                 test42.out test52.out test65.out test66.out test67.out \
1387                 test68.out test69.out test71.out test72.out test73.out \
1388 !               test74.out test75.out test76.out test77.out
1389   
1390   SCRIPTS32 =   test50.out test70.out
1391   
1392 *** ../vim-7.3.142/src/testdir/Make_ming.mak    2010-11-10 16:54:16.000000000 +0100
1393 --- src/testdir/Make_ming.mak   2011-03-03 17:04:32.000000000 +0100
1394 ***************
1395 *** 48,54 ****
1396                 test37.out test38.out test39.out test40.out test41.out \
1397                 test42.out test52.out test65.out test66.out test67.out \
1398                 test68.out test69.out test71.out test72.out test73.out \
1399 !               test74.out test75.out test76.out
1400   
1401   SCRIPTS32 =   test50.out test70.out
1402   
1403 --- 48,54 ----
1404                 test37.out test38.out test39.out test40.out test41.out \
1405                 test42.out test52.out test65.out test66.out test67.out \
1406                 test68.out test69.out test71.out test72.out test73.out \
1407 !               test74.out test75.out test76.out test77.out
1408   
1409   SCRIPTS32 =   test50.out test70.out
1410   
1411 *** ../vim-7.3.142/src/testdir/Make_os2.mak     2010-11-10 16:54:16.000000000 +0100
1412 --- src/testdir/Make_os2.mak    2011-03-03 17:04:48.000000000 +0100
1413 ***************
1414 *** 28,34 ****
1415                 test61.out test62.out test63.out test64.out test65.out \
1416                 test66.out test67.out test68.out test69.out test70.out \
1417                 test71.out test72.out test73.out test74.out test75.out \
1418 !               test76.out
1419   
1420   .SUFFIXES: .in .out
1421   
1422 --- 28,34 ----
1423                 test61.out test62.out test63.out test64.out test65.out \
1424                 test66.out test67.out test68.out test69.out test70.out \
1425                 test71.out test72.out test73.out test74.out test75.out \
1426 !               test76.out test77.out
1427   
1428   .SUFFIXES: .in .out
1429   
1430 *** ../vim-7.3.142/src/testdir/Makefile 2010-11-10 16:54:16.000000000 +0100
1431 --- src/testdir/Makefile        2011-03-22 17:03:25.000000000 +0100
1432 ***************
1433 *** 25,31 ****
1434                 test59.out test60.out test61.out test62.out test63.out \
1435                 test64.out test65.out test66.out test67.out test68.out \
1436                 test69.out test70.out test71.out test72.out test73.out \
1437 !               test74.out test75.out test76.out
1438   
1439   SCRIPTS_GUI = test16.out
1440   
1441 --- 25,31 ----
1442                 test59.out test60.out test61.out test62.out test63.out \
1443                 test64.out test65.out test66.out test67.out test68.out \
1444                 test69.out test70.out test71.out test72.out test73.out \
1445 !               test74.out test75.out test76.out test77.out
1446   
1447   SCRIPTS_GUI = test16.out
1448   
1449 ***************
1450 *** 71,77 ****
1451                   fi \
1452                 else echo $* NO OUTPUT >>test.log; \
1453                 fi"
1454 !       -rm -rf X* test.ok viminfo
1455   
1456   test49.out: test49.vim
1457   
1458 --- 71,77 ----
1459                   fi \
1460                 else echo $* NO OUTPUT >>test.log; \
1461                 fi"
1462 ! #     -rm -rf X* test.ok viminfo
1463   
1464   test49.out: test49.vim
1465   
1466 *** ../vim-7.3.142/src/testdir/test77.in        2011-03-03 21:59:10.000000000 +0100
1467 --- src/testdir/test77.in       2011-03-22 17:12:38.000000000 +0100
1468 ***************
1469 *** 0 ****
1470 --- 1,27 ----
1471 + Inserts 2 million lines with consecutive integers starting from 1
1472 + (essentially, the output of GNU's seq 1 2000000), writes them to Xtest
1473 + and writes its cksum to test.out.
1474
1475 + We need 2 million lines to trigger a call to mf_hash_grow().  If it would mess
1476 + up the lines the checksum would differ.
1477
1478 + cksum is part of POSIX and so should be available on most Unixes.
1479 + If it isn't available then the test will be skipped.
1480
1481 + STARTTEST
1482 + :so small.vim
1483 + :if !executable("cksum")
1484 + : e! test.ok
1485 + : w! test.out
1486 + : qa!
1487 + :endif
1488 + :set fileformat=unix undolevels=-1
1489 + ggdG
1490 + :let i = 1
1491 + :while i <= 2000000 | call append(i, range(i, i + 99)) | let i += 100 | endwhile
1492 + ggdd
1493 + :w! Xtest
1494 + :!cksum Xtest > test.out
1495 + :qa!
1496 + ENDTEST
1497
1498 *** ../vim-7.3.142/src/testdir/test77.ok        2011-03-03 21:59:10.000000000 +0100
1499 --- src/testdir/test77.ok       2011-03-22 17:10:14.000000000 +0100
1500 ***************
1501 *** 0 ****
1502 --- 1 ----
1503 + 3678979763 14888896 Xtest
1504 *** ../vim-7.3.142/src/version.c        2011-03-22 15:47:18.000000000 +0100
1505 --- src/version.c       2011-03-22 18:01:48.000000000 +0100
1506 ***************
1507 *** 716,717 ****
1508 --- 716,719 ----
1509   {   /* Add new patch number below this line */
1510 + /**/
1511 +     143,
1512   /**/
1513
1514 -- 
1515 SIGIRO -- irony detected (iron core dumped)
1516
1517  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
1518 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
1519 \\\  an exciting new programming language -- http://www.Zimbu.org        ///
1520  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
This page took 0.14132 seconds and 3 git commands to generate.