command-t 1.5.1 → 1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65e092a4101159c349fa3add3f4654a8ea0ce323
4
+ data.tar.gz: 0da32ec23fd4db0d33aae16ae131201161872e16
5
+ SHA512:
6
+ metadata.gz: 15aee07c8cbf2e2f6d1dbf5b2da4731adb9a5f359d8a0f4a783d2e9eb998eb56cc4ae2d72d3e4ac4a4bc87a1465f99c63b1dea1f131124869475403c599cf489
7
+ data.tar.gz: 75ead8da5ba910874aa4172f4c7558e63e4cd95923a9db2daa37ea319a41d5dd8761994117ab81307d9c734085d2dbef49cbd89b1acb8fb2f1552d7a53ce9b3e
data/README.txt CHANGED
@@ -764,6 +764,11 @@ POSSIBILITY OF SUCH DAMAGE.
764
764
 
765
765
  HISTORY *command-t-history*
766
766
 
767
+ 1.6 (16 December 2013)
768
+ - on systems with POSIX threads (such as OS X and Linux), Command-T will use
769
+ threads to compute match results in parallel, resulting in a large speed
770
+ boost that is especially noticeable when navigating large projects
771
+
767
772
  1.5.1 (23 September 2013)
768
773
  - exclude large benchmark fixture file from source exports (patch from Vít
769
774
  Ondruch)
data/doc/command-t.txt CHANGED
@@ -764,6 +764,11 @@ POSSIBILITY OF SUCH DAMAGE.
764
764
 
765
765
  HISTORY *command-t-history*
766
766
 
767
+ 1.6 (16 December 2013)
768
+ - on systems with POSIX threads (such as OS X and Linux), Command-T will use
769
+ threads to compute match results in parallel, resulting in a large speed
770
+ boost that is especially noticeable when navigating large projects
771
+
767
772
  1.5.1 (23 September 2013)
768
773
  - exclude large benchmark fixture file from source exports (patch from Vít
769
774
  Ondruch)
@@ -1,75 +1,120 @@
1
1
 
2
2
  SHELL = /bin/sh
3
3
 
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ ECHO1 = $(V:1=@:)
9
+ ECHO = $(ECHO1:0=@echo)
10
+
4
11
  #### Start of system configuration section. ####
5
12
 
6
13
  srcdir = .
7
- topdir = /Users/greg/.multiruby/install/1.8.7-p334/lib/ruby/1.8/i686-darwin10.6.0
14
+ topdir = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0
8
15
  hdrdir = $(topdir)
9
- VPATH = $(srcdir):$(topdir):$(hdrdir)
16
+ arch_hdrdir = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin13
17
+ PATH_SEPARATOR = :
18
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
19
+ prefix = /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr
20
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
21
+ rubyarchprefix = $(rubylibprefix)/$(arch)
22
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
10
23
  exec_prefix = $(prefix)
11
- prefix = $(DESTDIR)/Users/greg/.multiruby/install/1.8.7-p334
12
- sharedstatedir = $(prefix)/com
13
- mandir = $(datarootdir)/man
14
- psdir = $(docdir)
15
- oldincludedir = $(DESTDIR)/usr/include
16
- localedir = $(datarootdir)/locale
17
- bindir = $(exec_prefix)/bin
18
- libexecdir = $(exec_prefix)/libexec
19
- sitedir = $(libdir)/ruby/site_ruby
20
- htmldir = $(docdir)
24
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
25
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
26
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
27
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
28
+ sitehdrdir = $(rubyhdrdir)/site_ruby
29
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
21
30
  vendorarchdir = $(vendorlibdir)/$(sitearch)
22
- includedir = $(prefix)/include
23
- infodir = $(datarootdir)/info
24
31
  vendorlibdir = $(vendordir)/$(ruby_version)
25
- sysconfdir = $(prefix)/etc
32
+ vendordir = $(rubylibprefix)/vendor_ruby
33
+ sitearchdir = $(sitelibdir)/$(sitearch)
34
+ sitelibdir = $(sitedir)/$(ruby_version)
35
+ sitedir = $(DESTDIR)/Library/Ruby/Site
36
+ rubyarchdir = $(rubylibdir)/$(arch)
37
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
38
+ sitearchincludedir = $(includedir)/$(sitearch)
39
+ archincludedir = $(includedir)/$(arch)
40
+ sitearchlibdir = $(libdir)/$(sitearch)
41
+ archlibdir = $(libdir)/$(arch)
42
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
43
+ mandir = $(DESTDIR)/usr/share/man
44
+ localedir = $(datarootdir)/locale
26
45
  libdir = $(exec_prefix)/lib
27
- sbindir = $(exec_prefix)/sbin
28
- rubylibdir = $(libdir)/ruby/$(ruby_version)
29
- docdir = $(datarootdir)/doc/$(PACKAGE)
30
- dvidir = $(docdir)
31
- vendordir = $(libdir)/ruby/vendor_ruby
32
- datarootdir = $(prefix)/share
46
+ psdir = $(docdir)
33
47
  pdfdir = $(docdir)
34
- archdir = $(rubylibdir)/$(arch)
35
- sitearchdir = $(sitelibdir)/$(sitearch)
36
- datadir = $(datarootdir)
48
+ dvidir = $(docdir)
49
+ htmldir = $(docdir)
50
+ infodir = $(DESTDIR)/usr/share/info
51
+ docdir = $(datarootdir)/doc/$(PACKAGE)
52
+ oldincludedir = /usr/include
53
+ includedir = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk$(prefix)/include
37
54
  localstatedir = $(prefix)/var
38
- sitelibdir = $(sitedir)/$(ruby_version)
55
+ sharedstatedir = $(prefix)/com
56
+ sysconfdir = $(DESTDIR)/Library/Ruby/Site
57
+ datadir = $(datarootdir)
58
+ datarootdir = $(prefix)/share
59
+ libexecdir = $(exec_prefix)/libexec
60
+ sbindir = $(exec_prefix)/sbin
61
+ bindir = $(exec_prefix)/bin
62
+ archdir = $(rubyarchdir)
63
+
39
64
 
40
- CC = gcc
65
+ CC = xcrun clang
66
+ CXX = xcrun clang++
41
67
  LIBRUBY = $(LIBRUBY_SO)
42
68
  LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
43
69
  LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
44
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
70
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
71
+ empty =
72
+ OUTFLAG = -o $(empty)
73
+ COUTFLAG = -o $(empty)
45
74
 
46
75
  RUBY_EXTCONF_H =
47
- CFLAGS = -fno-common -g -O2 -fno-common -pipe -fno-common $(cflags)
48
- INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
49
- DEFS =
50
- CPPFLAGS = -DHAVE_RUBY_H -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
51
- CXXFLAGS = $(CFLAGS)
52
- ldflags = -L.
53
- dldflags =
54
- archflag =
55
- DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
56
- LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
76
+ cflags = $(optflags) $(debugflags) $(warnflags)
77
+ optflags =
78
+ debugflags = -g
79
+ warnflags =
80
+ CCDLFLAGS =
81
+ CFLAGS = $(CCDLFLAGS) -g -Os -pipe $(ARCH_FLAG)
82
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
83
+ DEFS = -DPROCESSOR_COUNT=4
84
+ CPPFLAGS = -DHAVE_PTHREAD_H -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
85
+ CXXFLAGS = $(CCDLFLAGS) -g -Os -pipe $(ARCH_FLAG)
86
+ ldflags = -L. -L/usr/local/lib
87
+ dldflags = -undefineddynamic_lookup -multiply_definedsuppress
88
+ ARCH_FLAG =
89
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
90
+ LDSHARED = $(CC) -dynamic -bundle
91
+ LDSHAREDXX = $(CXX) -dynamic -bundle
57
92
  AR = ar
58
93
  EXEEXT =
59
94
 
60
95
  RUBY_INSTALL_NAME = ruby
61
- RUBY_SO_NAME = ruby
62
- arch = i686-darwin10.6.0
63
- sitearch = i686-darwin10.6.0
64
- ruby_version = 1.8
65
- ruby = /Users/greg/.multiruby/install/1.8.7-p334/bin/ruby
96
+ RUBY_SO_NAME = ruby.2.0.0
97
+ RUBYW_INSTALL_NAME =
98
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
99
+ RUBYW_BASE_NAME = rubyw
100
+ RUBY_BASE_NAME = ruby
101
+
102
+ arch = universal-darwin13
103
+ sitearch = $(arch)
104
+ ruby_version = 2.0.0
105
+ ruby = $(bindir)/ruby
66
106
  RUBY = $(ruby)
107
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h
108
+
67
109
  RM = rm -f
110
+ RM_RF = $(RUBY) -run -e rm -- -rf
111
+ RMDIRS = rmdir -p
68
112
  MAKEDIRS = mkdir -p
69
113
  INSTALL = /usr/bin/install -c
70
114
  INSTALL_PROG = $(INSTALL) -m 0755
71
115
  INSTALL_DATA = $(INSTALL) -m 644
72
116
  COPY = cp
117
+ TOUCH = exit >
73
118
 
74
119
  #### End of system configuration section. ####
75
120
 
@@ -81,76 +126,112 @@ DEFFILE =
81
126
 
82
127
  CLEANFILES = mkmf.log
83
128
  DISTCLEANFILES =
129
+ DISTCLEANDIRS =
84
130
 
85
131
  extout =
86
132
  extout_prefix =
87
133
  target_prefix =
88
134
  LOCAL_LIBS =
89
- LIBS = $(LIBRUBYARG_SHARED) -ldl -lobjc
90
- SRCS = ext.c match.c matcher.c
135
+ LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lobjc
136
+ ORIG_SRCS = ext.c match.c matcher.c
137
+ SRCS = $(ORIG_SRCS)
91
138
  OBJS = ext.o match.o matcher.o
139
+ HDRS = $(srcdir)/ext.h $(srcdir)/match.h $(srcdir)/matcher.h $(srcdir)/ruby_compat.h
92
140
  TARGET = ext
141
+ TARGET_NAME = ext
142
+ TARGET_ENTRY = Init_$(TARGET_NAME)
93
143
  DLLIB = $(TARGET).bundle
94
144
  EXTSTATIC =
95
145
  STATIC_LIB =
96
146
 
97
- BINDIR = $(bindir)
98
- RUBYCOMMONDIR = $(sitedir)$(target_prefix)
99
- RUBYLIBDIR = $(sitelibdir)$(target_prefix)
100
- RUBYARCHDIR = $(sitearchdir)$(target_prefix)
147
+ BINDIR = $(DESTDIR)$(bindir)
148
+ RUBYCOMMONDIR = $(DESTDIR)$(sitedir)$(target_prefix)
149
+ RUBYLIBDIR = $(DESTDIR)$(sitelibdir)$(target_prefix)
150
+ RUBYARCHDIR = $(DESTDIR)$(sitearchdir)$(target_prefix)
151
+ HDRDIR = $(DESTDIR)$(rubyhdrdir)/ruby$(target_prefix)
152
+ ARCHHDRDIR = $(DESTDIR)$(rubyhdrdir)/$(arch)/ruby$(target_prefix)
101
153
 
102
154
  TARGET_SO = $(DLLIB)
103
- CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
104
- CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
155
+ CLEANLIBS = $(TARGET).bundle
156
+ CLEANOBJS = *.o *.bak
105
157
 
106
- all: $(DLLIB)
107
- static: $(STATIC_LIB)
158
+ all: $(DLLIB)
159
+ static: $(STATIC_LIB)
160
+ .PHONY: all install static install-so install-rb
161
+ .PHONY: clean clean-so clean-static clean-rb
108
162
 
109
- clean:
110
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
163
+ clean-static::
164
+ clean-rb-default::
165
+ clean-rb::
166
+ clean-so::
167
+ clean: clean-so clean-static clean-rb-default clean-rb
168
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
111
169
 
112
- distclean: clean
113
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
114
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
170
+ distclean-rb-default::
171
+ distclean-rb::
172
+ distclean-so::
173
+ distclean-static::
174
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
175
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
176
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
177
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
115
178
 
116
- realclean: distclean
179
+ realclean: distclean
117
180
  install: install-so install-rb
118
181
 
119
- install-so: $(RUBYARCHDIR)
120
- install-so: $(RUBYARCHDIR)/$(DLLIB)
121
- $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
182
+ install-so: $(DLLIB) ./.RUBYARCHDIR.time
122
183
  $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
184
+ clean-static::
185
+ -$(Q)$(RM) $(STATIC_LIB)
123
186
  install-rb: pre-install-rb install-rb-default
124
187
  install-rb-default: pre-install-rb-default
125
188
  pre-install-rb: Makefile
126
189
  pre-install-rb-default: Makefile
127
- $(RUBYARCHDIR):
128
- $(MAKEDIRS) $@
190
+ pre-install-rb-default:
191
+ $(ECHO) installing default ext libraries
192
+ ./.RUBYARCHDIR.time:
193
+ $(Q) $(MAKEDIRS) $(RUBYARCHDIR)
194
+ $(Q) $(TOUCH) $@
129
195
 
130
196
  site-install: site-install-so site-install-rb
131
197
  site-install-so: install-so
132
198
  site-install-rb: install-rb
133
199
 
134
- .SUFFIXES: .c .m .cc .cxx .cpp .C .o
200
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
135
201
 
136
202
  .cc.o:
137
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
203
+ $(ECHO) compiling $(<)
204
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
205
+
206
+ .mm.o:
207
+ $(ECHO) compiling $(<)
208
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
138
209
 
139
210
  .cxx.o:
140
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
211
+ $(ECHO) compiling $(<)
212
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
141
213
 
142
214
  .cpp.o:
143
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
215
+ $(ECHO) compiling $(<)
216
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
144
217
 
145
218
  .C.o:
146
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
219
+ $(ECHO) compiling $(<)
220
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
147
221
 
148
222
  .c.o:
149
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
223
+ $(ECHO) compiling $(<)
224
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
225
+
226
+ .m.o:
227
+ $(ECHO) compiling $(<)
228
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
150
229
 
151
230
  $(DLLIB): $(OBJS) Makefile
152
- @-$(RM) $@
153
- $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
231
+ $(ECHO) linking shared-object $(DLLIB)
232
+ -$(Q)$(RM) $(@)
233
+ $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
234
+ $(Q) test -z '$(RUBY_CODESIGN)' || codesign -s '$(RUBY_CODESIGN)' -f $@
154
235
 
155
236
 
156
237
 
Binary file
data/ruby/command-t/ext.c CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2010 Wincent Colaiuta. All rights reserved.
1
+ // Copyright 2010-2013 Wincent Colaiuta. All rights reserved.
2
2
  //
3
3
  // Redistribution and use in source and binary forms, with or without
4
4
  // modification, are permitted provided that the following conditions are met:
@@ -21,11 +21,9 @@
21
21
  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
22
  // POSSIBILITY OF SUCH DAMAGE.
23
23
 
24
- #include "match.h"
25
24
  #include "matcher.h"
26
25
 
27
26
  VALUE mCommandT = 0; // module CommandT
28
- VALUE cCommandTMatch = 0; // class CommandT::Match
29
27
  VALUE cCommandTMatcher = 0; // class CommandT::Matcher
30
28
 
31
29
  VALUE CommandT_option_from_hash(const char *option, VALUE hash)
@@ -44,22 +42,10 @@ void Init_ext()
44
42
  // module CommandT
45
43
  mCommandT = rb_define_module("CommandT");
46
44
 
47
- // class CommandT::Match
48
- cCommandTMatch = rb_define_class_under(mCommandT, "Match", rb_cObject);
49
-
50
- // methods
51
- rb_define_method(cCommandTMatch, "initialize", CommandTMatch_initialize, -1);
52
- rb_define_method(cCommandTMatch, "matches?", CommandTMatch_matches, 0);
53
- rb_define_method(cCommandTMatch, "to_s", CommandTMatch_to_s, 0);
54
-
55
- // attributes
56
- rb_define_attr(cCommandTMatch, "score", Qtrue, Qfalse); // reader: true, writer: false
57
-
58
45
  // class CommandT::Matcher
59
46
  cCommandTMatcher = rb_define_class_under(mCommandT, "Matcher", rb_cObject);
60
47
 
61
48
  // methods
62
49
  rb_define_method(cCommandTMatcher, "initialize", CommandTMatcher_initialize, -1);
63
- rb_define_method(cCommandTMatcher, "sorted_matches_for", CommandTMatcher_sorted_matches_for, 2);
64
- rb_define_method(cCommandTMatcher, "matches_for", CommandTMatcher_matches_for, 1);
50
+ rb_define_method(cCommandTMatcher, "sorted_matches_for", CommandTMatcher_sorted_matches_for, -1);
65
51
  }
data/ruby/command-t/ext.h CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2010 Wincent Colaiuta. All rights reserved.
1
+ // Copyright 2010-2013 Wincent Colaiuta. All rights reserved.
2
2
  //
3
3
  // Redistribution and use in source and binary forms, with or without
4
4
  // modification, are permitted provided that the following conditions are met:
@@ -24,7 +24,6 @@
24
24
  #include <ruby.h>
25
25
 
26
26
  extern VALUE mCommandT; // module CommandT
27
- extern VALUE cCommandTMatch; // class CommandT::Match
28
27
  extern VALUE cCommandTMatcher; // class CommandT::Matcher
29
28
 
30
29
  // Encapsulates common pattern of checking for an option in an optional
@@ -1,4 +1,4 @@
1
- # Copyright 2010 Wincent Colaiuta. All rights reserved.
1
+ # Copyright 2010-2013 Wincent Colaiuta. All rights reserved.
2
2
  #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions are met:
@@ -23,12 +23,82 @@
23
23
 
24
24
  require 'mkmf'
25
25
 
26
- def missing item
27
- puts "couldn't find #{item} (required)"
28
- exit 1
26
+ def header(item)
27
+ unless find_header(item)
28
+ puts "couldn't find #{item} (required)"
29
+ exit 1
30
+ end
29
31
  end
30
32
 
33
+ # Stolen, with minor modifications, from:
34
+ #
35
+ # https://github.com/grosser/parallel/blob/d11e4a3c8c1a2091a0cc2896befa71a94a88d1e7/lib/parallel.rb
36
+ #
37
+ # Number of processors seen by the OS and used for process scheduling.
38
+ #
39
+ # * AIX: /usr/sbin/pmcycles (AIX 5+), /usr/sbin/lsdev
40
+ # * BSD: /sbin/sysctl
41
+ # * Cygwin: /proc/cpuinfo
42
+ # * Darwin: /usr/bin/hwprefs, /usr/sbin/sysctl
43
+ # * HP-UX: /usr/sbin/ioscan
44
+ # * IRIX: /usr/sbin/sysconf
45
+ # * Linux: /proc/cpuinfo
46
+ # * Minix 3+: /proc/cpuinfo
47
+ # * Solaris: /usr/sbin/psrinfo
48
+ # * Tru64 UNIX: /usr/sbin/psrinfo
49
+ # * UnixWare: /usr/sbin/psrinfo
50
+ #
51
+ def processor_count
52
+ os_name = RbConfig::CONFIG['target_os']
53
+ if os_name =~ /mingw|mswin/
54
+ require 'win32ole'
55
+ result = WIN32OLE.connect('winmgmts://').ExecQuery(
56
+ 'select NumberOfLogicalProcessors from Win32_Processor')
57
+ result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
58
+ elsif File.readable?('/proc/cpuinfo')
59
+ IO.read('/proc/cpuinfo').scan(/^processor/).size
60
+ elsif File.executable?('/usr/bin/hwprefs')
61
+ IO.popen(%w[/usr/bin/hwprefs thread_count]).read.to_i
62
+ elsif File.executable?('/usr/sbin/psrinfo')
63
+ IO.popen('/usr/sbin/psrinfo').read.scan(/^.*on-*line/).size
64
+ elsif File.executable?('/usr/sbin/ioscan')
65
+ IO.popen(%w[/usr/sbin/ioscan -kC processor]) do |out|
66
+ out.read.scan(/^.*processor/).size
67
+ end
68
+ elsif File.executable?('/usr/sbin/pmcycles')
69
+ IO.popen(%w[/usr/sbin/pmcycles -m]).read.count("\n")
70
+ elsif File.executable?('/usr/sbin/lsdev')
71
+ IO.popen(%w[/usr/sbin/lsdev -Cc processor -S 1]).read.count("\n")
72
+ elsif File.executable?('/usr/sbin/sysconf') and os_name =~ /irix/i
73
+ IO.popen(%w[/usr/sbin/sysconf NPROC_ONLN]).read.to_i
74
+ elsif File.executable?('/usr/sbin/sysctl')
75
+ IO.popen(%w[/usr/sbin/sysctl -n hw.ncpu]).read.to_i
76
+ elsif File.executable?('/sbin/sysctl')
77
+ IO.popen(%w[/sbin/sysctl -n hw.ncpu]).read.to_i
78
+ else
79
+ puts 'Unknown platform: ' + RbConfig::CONFIG['target_os']
80
+ puts 'Assuming 1 processor.'
81
+ 1
82
+ end
83
+ rescue => e
84
+ puts "#{e}: assuming 1 processor."
85
+ 1
86
+ end
87
+
88
+ # mandatory headers
89
+ header('float.h')
90
+ header('ruby.h')
91
+ header('stdlib.h')
92
+ header('string.h')
93
+
94
+ # optional headers
95
+ have_header('pthread.h') # sets HAVE_PTHREAD_H if found
96
+
31
97
  RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
32
98
 
33
- have_header('ruby.h') or missing('ruby.h')
99
+ count = processor_count
100
+ count = 1 if count < 0 # sanity check
101
+ count = 32 if count > 32 # sanity check
102
+ RbConfig::MAKEFILE_CONFIG['DEFS'] += "-DPROCESSOR_COUNT=#{count}"
103
+
34
104
  create_makefile('ext')
@@ -21,7 +21,7 @@
21
21
  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
22
  // POSSIBILITY OF SUCH DAMAGE.
23
23
 
24
- #include "float.h"
24
+ #include <float.h> /* for DBL_MAX */
25
25
  #include "match.h"
26
26
  #include "ext.h"
27
27
  #include "ruby_compat.h"
@@ -146,20 +146,12 @@ memoize:
146
146
  return score;
147
147
  }
148
148
 
149
- // Match.new needle, string, options = {}
150
- VALUE CommandTMatch_initialize(int argc, VALUE *argv, VALUE self)
149
+ void calculate_match(VALUE str,
150
+ VALUE needle,
151
+ VALUE always_show_dot_files,
152
+ VALUE never_show_dot_files,
153
+ match_t *out)
151
154
  {
152
- // process arguments: 2 mandatory, 1 optional
153
- VALUE str, needle, options;
154
- if (rb_scan_args(argc, argv, "21", &str, &needle, &options) == 2)
155
- options = Qnil;
156
- str = StringValue(str);
157
- needle = StringValue(needle); // already downcased by caller
158
-
159
- // check optional options hash for overrides
160
- VALUE always_show_dot_files = CommandT_option_from_hash("always_show_dot_files", options);
161
- VALUE never_show_dot_files = CommandT_option_from_hash("never_show_dot_files", options);
162
-
163
155
  matchinfo_t m;
164
156
  m.haystack_p = RSTRING_PTR(str);
165
157
  m.haystack_len = RSTRING_LEN(str);
@@ -198,19 +190,7 @@ VALUE CommandTMatch_initialize(int argc, VALUE *argv, VALUE self)
198
190
  score = recursive_match(&m, 0, 0, 0, 0.0);
199
191
  }
200
192
 
201
- // clean-up and final book-keeping
202
- rb_iv_set(self, "@score", rb_float_new(score));
203
- rb_iv_set(self, "@str", str);
204
- return Qnil;
205
- }
206
-
207
- VALUE CommandTMatch_matches(VALUE self)
208
- {
209
- double score = NUM2DBL(rb_iv_get(self, "@score"));
210
- return score > 0 ? Qtrue : Qfalse;
211
- }
212
-
213
- VALUE CommandTMatch_to_s(VALUE self)
214
- {
215
- return rb_iv_get(self, "@str");
193
+ // final book-keeping
194
+ out->path = str;
195
+ out->score = score;
216
196
  }
@@ -1,4 +1,4 @@
1
- // Copyright 2010 Wincent Colaiuta. All rights reserved.
1
+ // Copyright 2010-2013 Wincent Colaiuta. All rights reserved.
2
2
  //
3
3
  // Redistribution and use in source and binary forms, with or without
4
4
  // modification, are permitted provided that the following conditions are met:
@@ -23,7 +23,14 @@
23
23
 
24
24
  #include <ruby.h>
25
25
 
26
- extern VALUE CommandTMatch_initialize(int argc, VALUE *argv, VALUE self);
27
- extern VALUE CommandTMatch_matches(VALUE self);
28
- extern VALUE CommandTMatch_score(VALUE self);
29
- extern VALUE CommandTMatch_to_s(VALUE self);
26
+ // struct for representing an individual match
27
+ typedef struct {
28
+ VALUE path;
29
+ double score;
30
+ } match_t;
31
+
32
+ extern void calculate_match(VALUE str,
33
+ VALUE needle,
34
+ VALUE always_show_dot_files,
35
+ VALUE never_show_dot_files,
36
+ match_t *out);
@@ -21,25 +21,30 @@
21
21
  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
22
  // POSSIBILITY OF SUCH DAMAGE.
23
23
 
24
- #include <stdlib.h> /* for qsort() */
25
- #include <string.h> /* for strcmp() */
24
+ #include <stdlib.h> /* for qsort() */
25
+ #include <string.h> /* for strncmp() */
26
26
  #include "matcher.h"
27
+ #include "match.h"
27
28
  #include "ext.h"
28
29
  #include "ruby_compat.h"
29
30
 
31
+ // order matters; we want this to be evaluated only after ruby.h
32
+ #ifdef HAVE_PTHREAD_H
33
+ #include <pthread.h> /* for pthread_create, pthread_join etc */
34
+ #endif
35
+
30
36
  // comparison function for use with qsort
31
- int comp_alpha(const void *a, const void *b)
37
+ int cmp_alpha(const void *a, const void *b)
32
38
  {
33
- VALUE a_val = *(VALUE *)a;
34
- VALUE b_val = *(VALUE *)b;
35
- ID to_s = rb_intern("to_s");
36
- VALUE a_str = rb_funcall(a_val, to_s, 0);
37
- VALUE b_str = rb_funcall(b_val, to_s, 0);
38
- char *a_p = RSTRING_PTR(a_str);
39
- long a_len = RSTRING_LEN(a_str);
40
- char *b_p = RSTRING_PTR(b_str);
41
- long b_len = RSTRING_LEN(b_str);
42
- int order = 0;
39
+ match_t a_match = *(match_t *)a;
40
+ match_t b_match = *(match_t *)b;
41
+ VALUE a_str = a_match.path;
42
+ VALUE b_str = b_match.path;
43
+ char *a_p = RSTRING_PTR(a_str);
44
+ long a_len = RSTRING_LEN(a_str);
45
+ char *b_p = RSTRING_PTR(b_str);
46
+ long b_len = RSTRING_LEN(b_str);
47
+ int order = 0;
43
48
 
44
49
  if (a_len > b_len) {
45
50
  order = strncmp(a_p, b_p, b_len);
@@ -57,20 +62,17 @@ int comp_alpha(const void *a, const void *b)
57
62
  }
58
63
 
59
64
  // comparison function for use with qsort
60
- int comp_score(const void *a, const void *b)
65
+ int cmp_score(const void *a, const void *b)
61
66
  {
62
- VALUE a_val = *(VALUE *)a;
63
- VALUE b_val = *(VALUE *)b;
64
- ID score = rb_intern("score");
65
- double a_score = RFLOAT_VALUE(rb_funcall(a_val, score, 0));
66
- double b_score = RFLOAT_VALUE(rb_funcall(b_val, score, 0));
67
+ match_t a_match = *(match_t *)a;
68
+ match_t b_match = *(match_t *)b;
67
69
 
68
- if (a_score > b_score)
70
+ if (a_match.score > b_match.score)
69
71
  return -1; // a scores higher, a should appear sooner
70
- else if (a_score < b_score)
72
+ else if (a_match.score < b_match.score)
71
73
  return 1; // b scores higher, a should appear later
72
74
  else
73
- return comp_alpha(a, b);
75
+ return cmp_alpha(a, b);
74
76
  }
75
77
 
76
78
  VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self)
@@ -87,12 +89,7 @@ VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self)
87
89
 
88
90
  // check optional options hash for overrides
89
91
  VALUE always_show_dot_files = CommandT_option_from_hash("always_show_dot_files", options);
90
- if (always_show_dot_files != Qtrue)
91
- always_show_dot_files = Qfalse;
92
-
93
92
  VALUE never_show_dot_files = CommandT_option_from_hash("never_show_dot_files", options);
94
- if (never_show_dot_files != Qtrue)
95
- never_show_dot_files = Qfalse;
96
93
 
97
94
  rb_iv_set(self, "@always_show_dot_files", always_show_dot_files);
98
95
  rb_iv_set(self, "@never_show_dot_files", never_show_dot_files);
@@ -100,70 +97,130 @@ VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self)
100
97
  return Qnil;
101
98
  }
102
99
 
103
- VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options)
100
+ typedef struct {
101
+ int thread_count;
102
+ int thread_index;
103
+ match_t *matches;
104
+ long path_count;
105
+ VALUE paths;
106
+ VALUE abbrev;
107
+ VALUE always_show_dot_files;
108
+ VALUE never_show_dot_files;
109
+ } thread_args_t;
110
+
111
+ void *match_thread(void *thread_args)
104
112
  {
105
- // process optional options hash
106
- VALUE limit_option = CommandT_option_from_hash("limit", options);
107
-
108
- // get unsorted matches
109
- VALUE matches = CommandTMatcher_matches_for(self, abbrev);
110
-
111
- abbrev = StringValue(abbrev);
112
- if (RSTRING_LEN(abbrev) == 0 ||
113
- (RSTRING_LEN(abbrev) == 1 && RSTRING_PTR(abbrev)[0] == '.'))
114
- // alphabetic order if search string is only "" or "."
115
- qsort(RARRAY_PTR(matches), RARRAY_LEN(matches), sizeof(VALUE), comp_alpha);
116
- else
117
- // for all other non-empty search strings, sort by score
118
- qsort(RARRAY_PTR(matches), RARRAY_LEN(matches), sizeof(VALUE), comp_score);
119
-
120
- // apply optional limit option
121
- long limit = NIL_P(limit_option) ? 0 : NUM2LONG(limit_option);
122
- if (limit == 0 || RARRAY_LEN(matches) < limit)
123
- limit = RARRAY_LEN(matches);
124
-
125
- // will return an array of strings, not an array of Match objects
126
- for (long i = 0; i < limit; i++) {
127
- VALUE str = rb_funcall(RARRAY_PTR(matches)[i], rb_intern("to_s"), 0);
128
- RARRAY_PTR(matches)[i] = str;
113
+ thread_args_t *args = (thread_args_t *)thread_args;
114
+ for (long i = args->thread_index; i < args->path_count; i += args->thread_count) {
115
+ VALUE path = RARRAY_PTR(args->paths)[i];
116
+ calculate_match(path,
117
+ args->abbrev,
118
+ args->always_show_dot_files,
119
+ args->never_show_dot_files,
120
+ &args->matches[i]);
129
121
  }
130
122
 
131
- // trim off any items beyond the limit
132
- if (limit < RARRAY_LEN(matches))
133
- (void)rb_funcall(matches, rb_intern("slice!"), 2, LONG2NUM(limit),
134
- LONG2NUM(RARRAY_LEN(matches) - limit));
135
-
136
- return matches;
123
+ return NULL;
137
124
  }
138
125
 
139
- VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev)
126
+
127
+ VALUE CommandTMatcher_sorted_matches_for(int argc, VALUE *argv, VALUE self)
140
128
  {
129
+ // process arguments: 1 mandatory, 1 optional
130
+ VALUE abbrev, options;
131
+
132
+ if (rb_scan_args(argc, argv, "11", &abbrev, &options) == 1)
133
+ options = Qnil;
141
134
  if (NIL_P(abbrev))
142
135
  rb_raise(rb_eArgError, "nil abbrev");
143
136
 
144
- VALUE matches = rb_ary_new();
137
+ abbrev = StringValue(abbrev);
138
+ abbrev = rb_funcall(abbrev, rb_intern("downcase"), 0);
139
+
140
+ // check optional options has for overrides
141
+ VALUE limit_option = CommandT_option_from_hash("limit", options);
142
+
143
+ // get unsorted matches
145
144
  VALUE scanner = rb_iv_get(self, "@scanner");
145
+ VALUE paths = rb_funcall(scanner, rb_intern("paths"), 0);
146
146
  VALUE always_show_dot_files = rb_iv_get(self, "@always_show_dot_files");
147
147
  VALUE never_show_dot_files = rb_iv_get(self, "@never_show_dot_files");
148
- VALUE options = Qnil;
149
-
150
- if (always_show_dot_files == Qtrue) {
151
- options = rb_hash_new();
152
- rb_hash_aset(options, ID2SYM(rb_intern("always_show_dot_files")), always_show_dot_files);
153
- } else if (never_show_dot_files == Qtrue) {
154
- options = rb_hash_new();
155
- rb_hash_aset(options, ID2SYM(rb_intern("never_show_dot_files")), never_show_dot_files);
148
+
149
+ long path_count = RARRAY_LEN(paths);
150
+ match_t *matches = malloc(path_count * sizeof(match_t));
151
+ if (!matches)
152
+ rb_raise(rb_eNoMemError, "memory allocation failed");
153
+
154
+ int err;
155
+ int thread_count = 1;
156
+
157
+ #ifdef HAVE_PTHREAD_H
158
+ #define THREAD_THRESHOLD 1000 /* avoid the overhead of threading when search space is small */
159
+ if (path_count < THREAD_THRESHOLD)
160
+ thread_count = 1;
161
+ else
162
+ thread_count = PROCESSOR_COUNT; // passed in as preprocessor macro
163
+ pthread_t *threads = malloc(sizeof(pthread_t) * thread_count);
164
+ if (!threads)
165
+ rb_raise(rb_eNoMemError, "memory allocation failed");
166
+ #endif
167
+
168
+ thread_args_t *thread_args = malloc(sizeof(thread_args_t) * thread_count);
169
+ if (!thread_args)
170
+ rb_raise(rb_eNoMemError, "memory allocation failed");
171
+ for (int i = 0; i < thread_count; i++) {
172
+ thread_args[i].thread_count = thread_count;
173
+ thread_args[i].thread_index = i;
174
+ thread_args[i].matches = matches;
175
+ thread_args[i].path_count = path_count;
176
+ thread_args[i].paths = paths;
177
+ thread_args[i].abbrev = abbrev;
178
+ thread_args[i].always_show_dot_files = always_show_dot_files;
179
+ thread_args[i].never_show_dot_files = never_show_dot_files;
180
+
181
+ #ifdef HAVE_PTHREAD_H
182
+ if (i == thread_count - 1) {
183
+ #endif
184
+ // for the last "worker", we'll just use the main thread
185
+ (void)match_thread(&thread_args[i]);
186
+ #ifdef HAVE_PTHREAD_H
187
+ } else {
188
+ err = pthread_create(&threads[i], NULL, match_thread, (void *)&thread_args[i]);
189
+ if (err != 0)
190
+ rb_raise(rb_eSystemCallError, "pthread_create() failure (%d)", err);
191
+ }
192
+ #endif
156
193
  }
157
194
 
158
- abbrev = rb_funcall(abbrev, rb_intern("downcase"), 0);
159
- VALUE paths = rb_funcall(scanner, rb_intern("paths"), 0);
195
+ #ifdef HAVE_PTHREAD_H
196
+ for (int i = 0; i < thread_count - 1; i++) {
197
+ err = pthread_join(threads[i], NULL);
198
+ if (err != 0)
199
+ rb_raise(rb_eSystemCallError, "pthread_join() failure (%d)", err);
200
+ }
201
+ free(threads);
202
+ #endif
203
+
204
+ if (RSTRING_LEN(abbrev) == 0 ||
205
+ (RSTRING_LEN(abbrev) == 1 && RSTRING_PTR(abbrev)[0] == '.'))
206
+ // alphabetic order if search string is only "" or "."
207
+ qsort(matches, path_count, sizeof(match_t), cmp_alpha);
208
+ else
209
+ // for all other non-empty search strings, sort by score
210
+ qsort(matches, path_count, sizeof(match_t), cmp_score);
160
211
 
161
- for (long i = 0, max = RARRAY_LEN(paths); i < max; i++) {
162
- VALUE path = RARRAY_PTR(paths)[i];
163
- VALUE match = rb_funcall(cCommandTMatch, rb_intern("new"), 3, path, abbrev, options);
164
- if (rb_funcall(match, rb_intern("matches?"), 0) == Qtrue)
165
- rb_funcall(matches, rb_intern("push"), 1, match);
212
+ VALUE results = rb_ary_new();
213
+
214
+ long limit = NIL_P(limit_option) ? 0 : NUM2LONG(limit_option);
215
+ if (limit == 0)
216
+ limit = path_count;
217
+ for (long i = 0; i < path_count && limit > 0; i++) {
218
+ if (matches[i].score > 0.0) {
219
+ rb_funcall(results, rb_intern("push"), 1, matches[i].path);
220
+ limit--;
221
+ }
166
222
  }
167
223
 
168
- return matches;
224
+ free(matches);
225
+ return results;
169
226
  }
@@ -1,4 +1,4 @@
1
- // Copyright 2010 Wincent Colaiuta. All rights reserved.
1
+ // Copyright 2010-2013 Wincent Colaiuta. All rights reserved.
2
2
  //
3
3
  // Redistribution and use in source and binary forms, with or without
4
4
  // modification, are permitted provided that the following conditions are met:
@@ -24,7 +24,4 @@
24
24
  #include <ruby.h>
25
25
 
26
26
  extern VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self);
27
- extern VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options);
28
-
29
- // most likely the function will be subsumed by the sorted_matcher_for function
30
- extern VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev);
27
+ extern VALUE CommandTMatcher_sorted_matches_for(int argc, VALUE *argv, VALUE self);
metadata CHANGED
@@ -1,32 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: command-t
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 5
8
- - 1
9
- version: 1.5.1
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.6'
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Wincent Colaiuta
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2011-01-05 00:00:00 -08:00
18
- default_executable:
11
+ date: 2013-12-16 00:00:00.000000000 Z
19
12
  dependencies: []
20
-
21
- description: " Command-T provides a fast, intuitive mechanism for opening files with a\n minimal number of keystrokes. Its full functionality is only available when\n installed as a Vim plug-in, but it is also made available as a RubyGem so\n that other applications can make use of its searching algorithm.\n"
13
+ description: |2
14
+ Command-T provides a fast, intuitive mechanism for opening files with a
15
+ minimal number of keystrokes. Its full functionality is only available when
16
+ installed as a Vim plug-in, but it is also made available as a RubyGem so
17
+ that other applications can make use of its searching algorithm.
22
18
  email: win@wincent.com
23
19
  executables: []
24
-
25
- extensions:
20
+ extensions:
26
21
  - ruby/command-t/extconf.rb
27
22
  extra_rdoc_files: []
28
-
29
- files:
23
+ files:
30
24
  - README.txt
31
25
  - LICENSE
32
26
  - Gemfile
@@ -63,35 +57,27 @@ files:
63
57
  - ruby/command-t/vim.rb
64
58
  - doc/command-t.txt
65
59
  - plugin/command-t.vim
66
- has_rdoc: true
67
60
  homepage: https://wincent.com/products/command-t
68
61
  licenses: []
69
-
62
+ metadata: {}
70
63
  post_install_message:
71
64
  rdoc_options: []
72
-
73
- require_paths:
65
+ require_paths:
74
66
  - ruby
75
- required_ruby_version: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- segments:
80
- - 0
81
- version: "0"
82
- required_rubygems_version: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- segments:
87
- - 0
88
- version: "0"
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
89
77
  requirements: []
90
-
91
78
  rubyforge_project:
92
- rubygems_version: 1.3.6
79
+ rubygems_version: 2.0.3
93
80
  signing_key:
94
- specification_version: 3
81
+ specification_version: 4
95
82
  summary: The Command-T plug-in for VIM.
96
83
  test_files: []
97
-