Commit 69b6a9a1

69b6a9a10249Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified

Description

Implement Array#bsearch on int and string arrays

Binary-search a sorted typed array in find-minimum mode for the first element where the block is truthy, returning that element or nil. int arrays yield a nullable int (SP_INT_NIL), str arrays a string (NULL renders as nil). Other element kinds fall through to the unresolved path.

Refs #1216

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
69b6a9a10249
Parent
e26c4419b7fe

spinel_analyze.rbmodifiedView file

@@ -5593,10 +5593,18 @@
55935593 return "tuple:int,int"
55945594 end
55955595 # Integer Range#bsearch returns a member of the range or nil when
5596- # the block never finds one, so it is a nullable int.
5596+ # the block never finds one, so it is a nullable int. Array#bsearch
5597+ # returns an element of the (sorted) array or nil: int arrays yield a
5598+ # nullable int, str arrays a string (NULL renders as nil).
55975599 if mname == "bsearch" && @nd_block[nid] >= 0
5598- if recv >= 0 && infer_type(recv) == "range"
5599- return "int?"
5600+ if recv >= 0
5601+ rt_bs = infer_type(recv)
5602+ if rt_bs == "range" || rt_bs == "int_array"
5603+ return "int?"
5604+ end
5605+ if rt_bs == "str_array"
5606+ return "string"
5607+ end
56005608 end
56015609 end
56025610 if mname == "partition"