Skip to content
Myr

Started removal of Collection

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent e287b85 · Browse files · 7 files+11 added−144 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+11 added−144 removed

  • tests:+4 added−16 removed
  • other:+7 added−128 removed

7 files+11 added−144 removed

deleted:benchmarks/collection.js-111 removed
12require.paths.unshift('lib')3require.paths.unshift('benchmarks')4process.mixin(GLOBAL, require('sys'))5process.mixin(GLOBAL, require('benchmark'))6require('express')78print = puts910range = function(a, b) {11 var array = []12 while (a++ < b)13 array.push(a-1)14 return array15}1617suite('Collection with [0..10,000]', 100, function(){18 array = range(0, 10000)19 20 benchmark('for', function(){21 for (var i = 0, len = array.length; i < len; ++i) ;22 })23 24 benchmark('for uncached', function(){25 for (var i = 0; i < array.length; ++i) ;26 })27 28 benchmark('forEach()', function(){29 array.forEach(function(){})30 })31 32 benchmark('#each()', function(){33 $(array).each(function(){})34 })35 36 benchmark('#map()', function(){37 $(array).map(function(n){ return n += 1 })38 })39 40 benchmark('#map() with shorthand', function(){41 $(array).map('a += 1')42 })43 44 benchmark('#find()', function(){45 $(array).find(function(n){ return n > 5000 })46 })47 48 benchmark('#select()', function(){49 $(array).select(function(n){ return n % 2 })50 })51 52 benchmark('#first()', function(){53 $(array).first(5000)54 })55 56 benchmark('#slice()', function(){57 $(array).slice(100, 5000)58 })59 60 benchmark('#drop()', function(){61 $(array).drop(5000)62 })63 64 benchmark('#length()', function(){65 $(array).length()66 })67 68 benchmark('#keys()', function(){69 $(array).keys()70 })71 72 benchmark('#toArray()', function(){73 $(array).toArray()74 })75 76 benchmark('#min()', function(){77 $(array).min()78 })79 80 benchmark('#max()', function(){81 $(array).max()82 })83 84 benchmark('#sum()', function(){85 $(array).sum()86 })87 88 benchmark('#avg()', function(){89 $(array).avg()90 })91 92 benchmark('#clone()', function(){93 $(array).clone()94 })95 96 benchmark('#merge()', function(){97 $(array).merge({ foo: 'bar' })98 })99 100 benchmark('#sample()', function(){101 $(array).sample()102 })103 104 benchmark('#chunk()', function(){105 $(array).chunk(5)106 })107 108 benchmark('#at()', function(){109 $(array).at(5000)110 })111})
modified:lib/express/collection.js-11 removed
365 unmodified lines
366 })367 },368 369 /**370 * Return keys as a collection.371 *372 * @return {Collection}373 * @api public374 */375 376 keys: function() {377 return $(Object.keys(this.arr))378 },379 380 /**370 * Convert a collection to a true array.371 * Works recursively372 *373 * @return {array}
165 unmodified lines
modified:lib/express/core.js+5 added-5 removed
67 unmodified lines
68 */6970 normalize: function(path) {71 var self = this72 this.keys = []72 this.params = []73 if (path instanceof RegExp) return path74 return new RegExp('^' + utils.escapeRegexp(normalizePath(path), '.')75 .replace(/\*/g, '(.+)')76 .replace(/(\/|\\\.):(\w+)\?/g, function(_, c, key){77 self.keys.push(key)77 self.params.push(key)78 return '(?:' + c + '([^\/]+))?'79 })80 .replace(/:(\w+)/g, function(_, key){81 self.keys.push(key)81 self.params.push(key)82 return '([^\/]+)'83 }) + '$', 'i')84 }85})
62 unmodified lines
148 },149 150 /**151 * Map #request.captures to #request.params.path based on the152 * given _route_ keys.152 * given _route_ params.153 *154 * @param {Route} route155 * @api private156 */157 158 mapParams: function(route) {159 var self = this160 $(route.keys).each(function(key, i){160 $(route.params).each(function(key, i){161 self.request.params.path[key] = self.request.captures[++i]162 })163 }164})
174 unmodified lines
modified:lib/express.js+2 added
modified:spec/spec.collection.js+2 added-14 removed
266 unmodified lines
267 result.at(1).should.eql 'foobar'268 result.at(2).should.be_null269 end270 end271 272 describe '#keys()'273 it 'should return indices when array-like'274 $(['foo', 'bar']).keys().at(0).should.eql '0'275 $(['foo', 'bar']).keys().at(1).should.eql '1'276 end277 278 it 'should return keys when an object'279 $({ foo: 'bar', baz: 'raz' }).keys().at(0).should.eql 'foo'280 $({ foo: 'bar', baz: 'raz' }).keys().at(1).should.eql 'baz'281 end282 end283 271272 describe '#toArray()'273 it 'should return an array'286 $(['foo', 'bar']).keys().toArray().should.eql ['0', '1']274 $(['foo', 'bar']).keys.toArray().should.eql ['0', '1']275 end276 277 it 'should work on nested collections'278 $([$(['foo']), $(['bar'])]).toArray().should.eql [['foo'], ['bar']]
184 unmodified lines
modified:spec/spec.utils.js+2 added-2 removed
modified:Makefile-1 removed
16 unmodified lines
17app-upload:18 @$(NODE) examples/upload/app.js19 20benchmark:21 @$(NODE) benchmarks/collection.js21 @$(NODE) benchmarks/views.js22 23.PHONY: init test benchmark app