aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-29 12:01:08 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-29 12:01:08 -0700
commit068b184a59a98b4acdc63a2833c360199d138c1d (patch)
tree2eb628fc6d9ad09938033794739843ed16843a0a
parent26ed429976ac6486c0473f13b6e0f16e05ede484 (diff)
downloadrails-068b184a59a98b4acdc63a2833c360199d138c1d.tar.gz
rails-068b184a59a98b4acdc63a2833c360199d138c1d.tar.bz2
rails-068b184a59a98b4acdc63a2833c360199d138c1d.zip
PERF: removing many splats
-rw-r--r--lib/arel/algebra/relations/operations/group.rb2
-rw-r--r--lib/arel/algebra/relations/operations/having.rb2
-rw-r--r--lib/arel/algebra/relations/operations/order.rb2
-rw-r--r--lib/arel/algebra/relations/operations/project.rb2
-rw-r--r--lib/arel/algebra/relations/operations/where.rb2
-rw-r--r--lib/arel/algebra/relations/relation.rb14
-rw-r--r--spec/algebra/unit/relations/project_spec.rb6
-rw-r--r--spec/algebra/unit/relations/relation_spec.rb8
-rw-r--r--spec/engines/sql/unit/relations/group_spec.rb4
-rw-r--r--spec/engines/sql/unit/relations/order_spec.rb10
-rw-r--r--spec/engines/sql/unit/relations/project_spec.rb8
-rw-r--r--spec/engines/sql/unit/relations/where_spec.rb2
12 files changed, 30 insertions, 32 deletions
diff --git a/lib/arel/algebra/relations/operations/group.rb b/lib/arel/algebra/relations/operations/group.rb
index 89e56b3a98..f3666cacf8 100644
--- a/lib/arel/algebra/relations/operations/group.rb
+++ b/lib/arel/algebra/relations/operations/group.rb
@@ -2,7 +2,7 @@ module Arel
class Group < Compound
attr_reader :groupings
- def initialize(relation, *groupings)
+ def initialize(relation, groupings)
super(relation)
@groupings = groupings.collect { |g| g.bind(relation) }
end
diff --git a/lib/arel/algebra/relations/operations/having.rb b/lib/arel/algebra/relations/operations/having.rb
index 447e836c1a..d36aad071b 100644
--- a/lib/arel/algebra/relations/operations/having.rb
+++ b/lib/arel/algebra/relations/operations/having.rb
@@ -2,7 +2,7 @@ module Arel
class Having < Compound
attr_reader :predicates
- def initialize(relation, *predicates)
+ def initialize(relation, predicates)
super(relation)
@predicates = predicates.map { |p| p.bind(relation) }
end
diff --git a/lib/arel/algebra/relations/operations/order.rb b/lib/arel/algebra/relations/operations/order.rb
index 54be2f5af0..bf0e0f723c 100644
--- a/lib/arel/algebra/relations/operations/order.rb
+++ b/lib/arel/algebra/relations/operations/order.rb
@@ -2,7 +2,7 @@ module Arel
class Order < Compound
attr_reader :orderings
- def initialize(relation, *orderings)
+ def initialize(relation, orderings)
super(relation)
@orderings = orderings.collect { |o| o.bind(relation) }
end
diff --git a/lib/arel/algebra/relations/operations/project.rb b/lib/arel/algebra/relations/operations/project.rb
index 0590b8dd88..649ec19713 100644
--- a/lib/arel/algebra/relations/operations/project.rb
+++ b/lib/arel/algebra/relations/operations/project.rb
@@ -2,7 +2,7 @@ module Arel
class Project < Compound
attr_reader :projections, :attributes
- def initialize(relation, *projections)
+ def initialize(relation, projections)
super(relation)
@projections = projections.map { |p| p.bind(relation) }
@attributes = Header.new(projections.map { |x| x.bind(self) })
diff --git a/lib/arel/algebra/relations/operations/where.rb b/lib/arel/algebra/relations/operations/where.rb
index 3aa06406cf..3b70b49f3a 100644
--- a/lib/arel/algebra/relations/operations/where.rb
+++ b/lib/arel/algebra/relations/operations/where.rb
@@ -2,7 +2,7 @@ module Arel
class Where < Compound
attr_reader :predicates
- def initialize(relation, *predicates)
+ def initialize(relation, predicates)
super(relation)
@predicates = predicates.map { |p| p.bind(relation) }
@wheres = nil
diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb
index e8ef9b395d..dd0684b88e 100644
--- a/lib/arel/algebra/relations/relation.rb
+++ b/lib/arel/algebra/relations/relation.rb
@@ -116,19 +116,17 @@ module Arel
end
%w{
- where order skip group having
- }.each do |operation_name|
+ having group order where project
+ }.each do |op|
class_eval <<-OPERATION, __FILE__, __LINE__
- def #{operation_name}(*arguments)
- arguments.all? { |x| x.blank? } ?
- self : #{operation_name.capitalize}.new(self, *arguments)
+ def #{op}(*args)
+ args.all? { |x| x.blank? } ? self : #{op.capitalize}.new(self, args)
end
OPERATION
end
- def project *args
- return self if args.all? { |x| x.blank? }
- Project.new self, *args
+ def skip thing = nil
+ thing ? Skip.new(self, thing) : self
end
def take thing
diff --git a/spec/algebra/unit/relations/project_spec.rb b/spec/algebra/unit/relations/project_spec.rb
index 8886e65a2e..294bffafe9 100644
--- a/spec/algebra/unit/relations/project_spec.rb
+++ b/spec/algebra/unit/relations/project_spec.rb
@@ -9,7 +9,7 @@ module Arel
describe '#attributes' do
before do
- @projection = Project.new(@relation, @attribute)
+ @projection = Project.new(@relation, [@attribute])
end
it "manufactures attributes associated with the projection relation" do
@@ -20,13 +20,13 @@ module Arel
describe '#externalizable?' do
describe 'when the projections are attributes' do
it 'returns false' do
- Project.new(@relation, @attribute).should_not be_externalizable
+ Project.new(@relation, [@attribute]).should_not be_externalizable
end
end
describe 'when the projections include an aggregation' do
it "obtains" do
- Project.new(@relation, @attribute.sum).should be_externalizable
+ Project.new(@relation, [@attribute.sum]).should be_externalizable
end
end
end
diff --git a/spec/algebra/unit/relations/relation_spec.rb b/spec/algebra/unit/relations/relation_spec.rb
index 2a2fb15d89..f4769526da 100644
--- a/spec/algebra/unit/relations/relation_spec.rb
+++ b/spec/algebra/unit/relations/relation_spec.rb
@@ -97,11 +97,11 @@ module Arel
end
it "manufactures a where relation" do
- @relation.where(@predicate).should == Where.new(@relation, @predicate)
+ @relation.where(@predicate).should == Where.new(@relation, [@predicate])
end
it "accepts arbitrary strings" do
- @relation.where("arbitrary").should == Where.new(@relation, "arbitrary")
+ @relation.where("arbitrary").should == Where.new(@relation, ["arbitrary"])
end
describe 'when given a blank predicate' do
@@ -113,7 +113,7 @@ module Arel
describe '#order' do
it "manufactures an order relation" do
- @relation.order(@attribute1, @attribute2).should == Order.new(@relation, @attribute1, @attribute2)
+ @relation.order(@attribute1, @attribute2).should == Order.new(@relation, [@attribute1, @attribute2])
end
describe 'when given a blank ordering' do
@@ -149,7 +149,7 @@ module Arel
describe '#group' do
it 'manufactures a group relation' do
- @relation.group(@attribute1, @attribute2).should == Group.new(@relation, @attribute1, @attribute2)
+ @relation.group(@attribute1, @attribute2).should == Group.new(@relation, [@attribute1, @attribute2])
end
describe 'when given blank groupings' do
diff --git a/spec/engines/sql/unit/relations/group_spec.rb b/spec/engines/sql/unit/relations/group_spec.rb
index 72a9f4e99e..c32091bf08 100644
--- a/spec/engines/sql/unit/relations/group_spec.rb
+++ b/spec/engines/sql/unit/relations/group_spec.rb
@@ -10,7 +10,7 @@ module Arel
describe '#to_sql' do
describe 'when given a predicate' do
it "manufactures sql with where clause conditions" do
- sql = Group.new(@relation, @attribute).to_sql
+ sql = Group.new(@relation, [@attribute]).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
@@ -40,7 +40,7 @@ module Arel
describe 'when given a string' do
it "passes the string through to the where clause" do
- sql = Group.new(@relation, 'asdf').to_sql
+ sql = Group.new(@relation, ['asdf']).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
diff --git a/spec/engines/sql/unit/relations/order_spec.rb b/spec/engines/sql/unit/relations/order_spec.rb
index 3c9d9ef598..59637876bf 100644
--- a/spec/engines/sql/unit/relations/order_spec.rb
+++ b/spec/engines/sql/unit/relations/order_spec.rb
@@ -10,7 +10,7 @@ module Arel
describe '#to_sql' do
describe "when given an attribute" do
it "manufactures sql with an order clause populated by the attribute" do
- sql = Order.new(@relation, @attribute).to_sql
+ sql = Order.new(@relation, [@attribute]).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
@@ -60,7 +60,7 @@ module Arel
end
it "manufactures sql with an order clause populated by comma-separated attributes" do
- sql = Order.new(@relation, @attribute, @another_attribute).to_sql
+ sql = Order.new(@relation, [@attribute, @another_attribute]).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
@@ -94,7 +94,7 @@ module Arel
end
it "passes the string through to the order clause" do
- sql = Order.new(@relation, @string).to_sql
+ sql = Order.new(@relation, [@string]).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
@@ -124,12 +124,12 @@ module Arel
describe "when ordering an ordered relation" do
before do
- @ordered_relation = Order.new(@relation, @attribute)
+ @ordered_relation = Order.new(@relation, [@attribute])
@another_attribute = @relation[:name]
end
it "manufactures sql with the order clause of the last ordering preceding the first ordering" do
- sql = Order.new(@ordered_relation, @another_attribute).to_sql
+ sql = Order.new(@ordered_relation, [@another_attribute]).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
diff --git a/spec/engines/sql/unit/relations/project_spec.rb b/spec/engines/sql/unit/relations/project_spec.rb
index e73c7775a1..b5d2d33d4b 100644
--- a/spec/engines/sql/unit/relations/project_spec.rb
+++ b/spec/engines/sql/unit/relations/project_spec.rb
@@ -10,7 +10,7 @@ module Arel
describe '#to_sql' do
describe 'when given an attribute' do
it "manufactures sql with a limited select clause" do
- sql = Project.new(@relation, @attribute).to_sql
+ sql = Project.new(@relation, [@attribute]).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
@@ -37,11 +37,11 @@ module Arel
describe 'when given a relation' do
before do
- @scalar_relation = Project.new(@relation, @relation[:name])
+ @scalar_relation = Project.new(@relation, [@relation[:name]])
end
it "manufactures sql with scalar selects" do
- sql = Project.new(@relation, @scalar_relation).to_sql
+ sql = Project.new(@relation, [@scalar_relation]).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
@@ -65,7 +65,7 @@ module Arel
describe 'when given a string' do
it "passes the string through to the select clause" do
- sql = Project.new(@relation, 'asdf').to_sql
+ sql = Project.new(@relation, ['asdf']).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
diff --git a/spec/engines/sql/unit/relations/where_spec.rb b/spec/engines/sql/unit/relations/where_spec.rb
index 5f559efad3..69793d63a1 100644
--- a/spec/engines/sql/unit/relations/where_spec.rb
+++ b/spec/engines/sql/unit/relations/where_spec.rb
@@ -10,7 +10,7 @@ module Arel
describe '#to_sql' do
describe 'when given a predicate' do
it "manufactures sql with where clause conditions" do
- sql = Where.new(@relation, @predicate).to_sql
+ sql = Where.new(@relation, [@predicate]).to_sql
adapter_is :mysql do
sql.should be_like(%Q{