diff --git a/AppKit/CPColorPanel.j b/AppKit/CPColorPanel.j index d00baa311..e8a9320eb 100644 --- a/AppKit/CPColorPanel.j +++ b/AppKit/CPColorPanel.j @@ -483,13 +483,12 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie"; ]; } - var cookieValue = eval(cookieValue), - result = []; + var cookieValue = eval(cookieValue); - for (var i = 0; i < cookieValue.length; i++) - result.push([CPColor colorWithHexString:cookieValue[i]]); - - return result; + return [cookieValue arrayByApplyingBlock:function(value) + { + return [CPColor colorWithHexString:value]; + }]; } - (CPArray)saveColorList diff --git a/AppKit/CPComboBox.j b/AppKit/CPComboBox.j index b5aa1b7c2..61a159ed7 100644 --- a/AppKit/CPComboBox.j +++ b/AppKit/CPComboBox.j @@ -1142,11 +1142,9 @@ var CPComboBoxTextSubview = @"text", // Directly nuke _items, [_items removeAll] will trigger an extra call to setContent _items = []; - var values = []; - - [anArray enumerateObjectsUsingBlock:function(object) + var values = [anArray arrayByApplyingBlock:function(object) { - values.push([object description]); + return [object description]; }]; [self addItemsWithObjectValues:values]; diff --git a/AppKit/CPGradient.j b/AppKit/CPGradient.j index dfa7a3437..93b08b2d2 100644 --- a/AppKit/CPGradient.j +++ b/AppKit/CPGradient.j @@ -70,11 +70,12 @@ CPGradientDrawsAfterEndingLocation = kCGGradientDrawsAfterEndLocation; { if (self = [super init]) { - var cgColors = [], - count = [someColors count], - colorSpace = [aColorSpace CGColorSpace] || CGColorSpaceCreateDeviceRGB; - for (var i = 0; i < count; i++) - cgColors.push(CGColorCreate(colorSpace, [someColors[i] components])); + var colorSpace = [aColorSpace CGColorSpace] || CGColorSpaceCreateDeviceRGB, + cgColors = [someColors arrayByApplyingBlock:function(color) + { + return CGColorCreate(colorSpace, [color components]) + }]; + _gradient = CGGradientCreateWithColors(colorSpace, cgColors, someLocations); } diff --git a/AppKit/CPGraphics.j b/AppKit/CPGraphics.j index 380bea393..55dbb9f73 100644 --- a/AppKit/CPGraphics.j +++ b/AppKit/CPGraphics.j @@ -43,10 +43,10 @@ function CPDrawTiledRects( if (sides.length != grays.length) [CPException raise:CPInvalidArgumentException reason:@"sides (length: " + sides.length + ") and grays (length: " + grays.length + ") must have the same length."]; - var colors = []; - - for (var i = 0; i < grays.length; ++i) - colors.push([CPColor colorWithCalibratedWhite:grays[i] alpha:1.0]); + var colors = [grays arrayByApplyingBlock:function(gray) + { + return [CPColor colorWithCalibratedWhite:gray alpha:1.0]; + }]; return CPDrawColorTiledRects(boundsRect, clipRect, sides, colors); } diff --git a/AppKit/CPPopUpButton.j b/AppKit/CPPopUpButton.j index 09aecb6fe..6eecf9420 100644 --- a/AppKit/CPPopUpButton.j +++ b/AppKit/CPPopUpButton.j @@ -361,15 +361,10 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down"); */ - (CPArray)itemTitles { - var titles = [], - items = [self itemArray], - index = 0, - count = [items count]; - - for (; index < count; ++index) - titles.push([items[index] title]); - - return titles; + return [[self itemArray] arrayByApplyingBlock:function(item) + { + return [item title]; + }]; } /*! diff --git a/AppKit/CPThemeBlend.j b/AppKit/CPThemeBlend.j index 8455bd4c0..78cceaac3 100644 --- a/AppKit/CPThemeBlend.j +++ b/AppKit/CPThemeBlend.j @@ -64,12 +64,10 @@ */ - (CPArray)themeNames { - var names = []; - - for (var i = 0; i < _themes.length; ++i) - names.push(_themes[i].substring(0, _themes[i].indexOf(".keyedtheme"))); - - return names; + return [_themes arrayByApplyingBlock:function(theme) + { + return theme.substring(0, theme.indexOf(".keyedtheme")); + }]; } - (void)loadWithDelegate:(id)aDelegate diff --git a/AppKit/CPToolbar.j b/AppKit/CPToolbar.j index 49c78924e..b62aa82d6 100644 --- a/AppKit/CPToolbar.j +++ b/AppKit/CPToolbar.j @@ -459,11 +459,10 @@ var CPToolbarsByIdentifier = nil, /* @ignore */ - (id)_itemsWithIdentifiers:(CPArray)identifiers { - var items = []; - for (var i = 0; i < identifiers.length; i++) - [items addObject:[self _itemForItemIdentifier:identifiers[i] willBeInsertedIntoToolbar:NO]]; - - return items; + return [identifiers arrayByApplyingBlock:function(identifier) + { + return [self _itemForItemIdentifier:identifier willBeInsertedIntoToolbar:NO]; + }]; } /* @ignore */ diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index bb183bd99..fa54e8892 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -1857,11 +1857,10 @@ function CPWindowObjectList() function CPWindowList() { - var windowObjectList = CPWindowObjectList(), - windowList = []; + var windowObjectList = CPWindowObjectList(); - for (var i = 0, count = [windowObjectList count]; i < count; i++) - windowList.push([windowObjectList[i] windowNumber]); - - return windowList; + return [windowObjectList arrayByApplyingBlock:function(windowObject) + { + return [windowObject windowNumber]; + }]; } diff --git a/Foundation/CPArray/_CPArray.j b/Foundation/CPArray/_CPArray.j index 7607aa480..9a18fc879 100755 --- a/Foundation/CPArray/_CPArray.j +++ b/Foundation/CPArray/_CPArray.j @@ -881,22 +881,22 @@ Returns a hash for the object. Unlike Cocoa, the hash value does not take conten } /*! - Returns an Array formed by applying a function to the objects in the receiver. + Returns an Array formed by applying a function to each object in the receiver. @param aFunction a function taking two arguments: (element, index). @return an Array containing the transformed elements. */ - (CPArray)arrayByApplyingBlock:(Function/*element, index*/)aFunction { - var result = [], - count = [self count]; + var result = [], + count = [self count]; - for (var idx = 0; idx < count; idx++) - { - var obj = aFunction([self objectAtIndex:idx], idx); - [result addObject:obj]; - } + for (var idx = 0; idx < count; idx++) + { + var obj = aFunction([self objectAtIndex:idx], idx); + [result addObject:obj]; + } - return result; + return result; } // Creating a description of the array diff --git a/Foundation/CPArray/_CPJavaScriptArray.j b/Foundation/CPArray/_CPJavaScriptArray.j index 6d36a8586..8822ed0b4 100644 --- a/Foundation/CPArray/_CPJavaScriptArray.j +++ b/Foundation/CPArray/_CPJavaScriptArray.j @@ -235,15 +235,15 @@ var concat = Array.prototype.concat, - (CPArray)arrayByApplyingBlock:(Function/*element, index*/)aFunction { - var result = []; + var result = []; - for (var idx = 0; idx < self.length; idx++) - { - var obj = aFunction(self[idx], idx); - result.push(obj); - } + for (var idx = 0; idx < self.length; idx++) + { + var obj = aFunction(self[idx], idx); + result.push(obj); + } - return result; + return result; } - (void)insertObject:(id)anObject atIndex:(CPUInteger)anIndex diff --git a/Foundation/CPAttributedString.j b/Foundation/CPAttributedString.j index 04c131631..3416b64bc 100755 --- a/Foundation/CPAttributedString.j +++ b/Foundation/CPAttributedString.j @@ -763,13 +763,10 @@ - (void)setAttributedString:(CPAttributedString)aString { _string = aString._string; - _rangeEntries = []; - - var i = 0, - count = aString._rangeEntries.length; - - for (; i < count; i++) - _rangeEntries.push(copyRangeEntry(aString._rangeEntries[i])); + _rangeEntries = [aString._rangeEntries arrayByApplyingBlock:function(entry) + { + return copyRangeEntry(entry); + }]; } //Private methods diff --git a/Foundation/CPBundle.j b/Foundation/CPBundle.j index 069e0e6eb..fa752574a 100644 --- a/Foundation/CPBundle.j +++ b/Foundation/CPBundle.j @@ -212,15 +212,12 @@ var CPBundlesForURLStrings = { }; - (CPArray)staticResourceURLs { - var staticResourceURLs = [], - staticResources = _bundle.staticResources(), - index = 0, - count = [staticResources count]; + var staticResources = _bundle.staticResources(); - for (; index < count; ++index) - [staticResourceURLs addObject:staticResources[index].URL()]; - - return staticResourceURLs; + return [staticResources arrayByApplyingBlock:function(resource) + { + return resource.URL(); + }]; } - (CPArray)environments diff --git a/Foundation/CPIndexSet.j b/Foundation/CPIndexSet.j index c9f94fddb..1783caf27 100644 --- a/Foundation/CPIndexSet.j +++ b/Foundation/CPIndexSet.j @@ -1018,14 +1018,13 @@ var CPIndexSetCountKey = @"CPIndexSetCountKey", if (self) { _count = [aCoder decodeIntForKey:CPIndexSetCountKey]; - _ranges = []; - var rangeStrings = [aCoder decodeObjectForKey:CPIndexSetRangeStringsKey], - index = 0, - count = rangeStrings.length; + var rangeStrings = [aCoder decodeObjectForKey:CPIndexSetRangeStringsKey]; - for (; index < count; ++index) - _ranges.push(CPRangeFromString(rangeStrings[index])); + _ranges = [rangeStrings arrayByApplyingBlock:function(range) + { + return CPRangeFromString(range); + }]; } return self; diff --git a/Foundation/CPKeyedArchiver.j b/Foundation/CPKeyedArchiver.j index e4e0d7bbd..20bb7b4be 100644 --- a/Foundation/CPKeyedArchiver.j +++ b/Foundation/CPKeyedArchiver.j @@ -380,12 +380,10 @@ var _CPKeyedArchiverStringClass = Nil, /* @ignore */ - (void)_encodeArrayOfObjects:(CPArray)objects forKey:(CPString)aKey { - var i = 0, - count = objects.length, - references = []; - - for (; i < count; ++i) - [references addObject:_CPKeyedArchiverEncodeObject(self, objects[i], NO)]; + var references = [objects arrayByApplyingBlock:function(object) + { + return _CPKeyedArchiverEncodeObject(self, object, NO); + }]; [_plistObject setObject:references forKey:aKey]; } diff --git a/Foundation/CPPredicate/_CPAggregateExpression.j b/Foundation/CPPredicate/_CPAggregateExpression.j index 2216c959c..e141b1915 100644 --- a/Foundation/CPPredicate/_CPAggregateExpression.j +++ b/Foundation/CPPredicate/_CPAggregateExpression.j @@ -34,6 +34,7 @@ if (self) _aggregate = collection; + return self; } @@ -50,41 +51,28 @@ - (id)expressionValueWithObject:(id)object context:(CPDictionary)context { - var eval_array = [CPArray array], - collection = [_aggregate objectEnumerator], - exp; - - while ((exp = [collection nextObject]) !== nil) + return [_aggregate arrayByApplyingBlock:function(exp) { - var eval = [exp expressionValueWithObject:object context:context]; - [eval_array addObject:eval]; - } - - return eval_array; + return [exp expressionValueWithObject:object context:context]; + }]; } - (CPString)description -{ - var i = 0, - count = [_aggregate count], - result = "{"; +{ + var descriptions = [_aggregate arrayByApplyingBlock:function(exp) + { + return [exp description]; + }]; - for (; i < count; i++) - result = result + [CPString stringWithFormat:@"%s%s", [[_aggregate objectAtIndex:i] description], (i + 1 < count) ? @", " : @""]; - - result = result + "}"; - - return result; + return "{" + [descriptions componentsJoinedByString:","] + "}" ; } - (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables { - var subst_array = [CPArray array], - count = [_aggregate count], - i = 0; - - for (; i < count; i++) - [subst_array addObject:[[_aggregate objectAtIndex:i] _expressionWithSubstitutionVariables:variables]]; + var subst_array = [_aggregate arrayByApplyingBlock:function(exp) + { + return [exp _expressionWithSubstitutionVariables:variables]; + }]; return [CPExpression expressionForAggregate:subst_array]; } diff --git a/Foundation/CPPredicate/_CPBlockExpression.j b/Foundation/CPPredicate/_CPBlockExpression.j index 299f250ee..846c4f418 100644 --- a/Foundation/CPPredicate/_CPBlockExpression.j +++ b/Foundation/CPPredicate/_CPBlockExpression.j @@ -53,11 +53,9 @@ - (id)expressionValueWithObject:(id)object context:(CPDictionary)context { - var args = []; - - [_arguments enumerateObjectsUsingBlock:function(exp, idx) + var args = [_arguments arrayByApplyingBlock:function(exp) { - [args addObject:[exp expressionValueWithObject:object context:context]]; + return [exp expressionValueWithObject:object context:context]; }]; return _block(object, args, context); @@ -65,11 +63,9 @@ - (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)bindings { - var args = []; - - [_arguments enumerateObjectsUsingBlock:function(exp, idx) + var args = [_arguments arrayByApplyingBlock:function(exp) { - [args addObject:[exp _expressionWithSubstitutionVariables:bindings]]; + return [exp _expressionWithSubstitutionVariables:bindings]; }]; return [[_CPBlockExpression alloc] initWithBlock:_block arguments:args]; diff --git a/Foundation/CPPredicate/_CPFunctionExpression.j b/Foundation/CPPredicate/_CPFunctionExpression.j index 32790d4e4..7de9f0d73 100644 --- a/Foundation/CPPredicate/_CPFunctionExpression.j +++ b/Foundation/CPPredicate/_CPFunctionExpression.j @@ -133,11 +133,10 @@ - (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables { var operand = [[self operand] _expressionWithSubstitutionVariables:variables], - args = [CPArray array], - i = 0; - - for (; i < _argc; i++) - [args addObject:[_arguments[i] _expressionWithSubstitutionVariables:variables]]; + args = [_arguments arrayByApplyingBlock:function(arg) + { + return [arg _expressionWithSubstitutionVariables:variables]; + }]; return [CPExpression expressionForFunction:operand selectorName:[self _function] arguments:args]; }