Skip to content

Commit ced6ecf

Browse files
committed
Make first safer.
1 parent d86b7c2 commit ced6ecf

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

indexes/ext/arrays.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ impl Array {
9898
self.data.first()
9999
}
100100

101-
pub fn first_amount(&mut self, amount: usize) -> Array {
101+
pub fn first_amount(&mut self, mut amount: usize) -> Array {
102+
// Check for length.
103+
let length = self.length();
104+
if amount > length { amount = length; }
102105
let mut vector = Vec::with_capacity(amount);
103106
vector.extend(self.data[0..amount].iter().cloned());
104107
Array {
8 Bytes
Binary file not shown.

indexes/lib/picky-indexes/rust/array.rb

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ module ArrayBackend
3030
attach_function :rust_array_sort_by_bang, [:pointer, :rust_array_sort_by_bang_callback], :pointer
3131
attach_function :rust_array_dup, [:pointer], :pointer
3232
attach_function :rust_array_inspect, [:pointer], :string
33+
34+
# attach_function :rust_array_find, [:pointer, :uint16], :uint16
35+
# attach_function :rust_array_reject, [:pointer, :uint16], :uint16
3336
end
3437

3538
class Array < FFI::AutoPointer
@@ -130,6 +133,7 @@ def include? item
130133

131134
def sort_by! &block
132135
return self unless block_given?
136+
return self if size < 2
133137

134138
@internal_instance = rust_array_sort_by_bang(to_ptr, block)
135139

server/lib/picky/query/allocation.rb

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def process_with_illegals! amount, offset, illegal_ids, sorting = nil
101101
#
102102
calculated_ids = calculate_ids amount + illegal_ids.size, offset
103103
calculated_ids = calculated_ids - illegal_ids
104-
p [:process_with_illegals!, calculated_ids, sorting]
105104
calculated_ids.sort_by! &sorting if sorting
106105
@count = calculated_ids.size # cache the count before throwing away the ids
107106
@ids = calculated_ids.slice!(offset, amount) || [] # slice out the relevant part

server/lib/picky/query/combination/or.rb

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def weight
3636
# Note: Caching is most of the time useful.
3737
#
3838
def ids
39+
# FIXME Use empty_array from bundle!
3940
@ids ||= @combinations.inject([]) do |total, combination|
4041
total + combination.ids
4142
end.uniq

0 commit comments

Comments
 (0)