(args: &[ArrayRef])
| 160 | } |
| 161 | |
| 162 | fn replace_view(args: &[ArrayRef]) -> Result<ArrayRef> { |
| 163 | let string_array = as_string_view_array(&args[0])?; |
| 164 | let from_array = as_string_view_array(&args[1])?; |
| 165 | let to_array = as_string_view_array(&args[2])?; |
| 166 | |
| 167 | let len = string_array.len(); |
| 168 | let mut builder = GenericStringArrayBuilder::<i32>::with_capacity(len, 0); |
| 169 | let nulls = NullBuffer::union_many([ |
| 170 | string_array.nulls(), |
| 171 | from_array.nulls(), |
| 172 | to_array.nulls(), |
| 173 | ]); |
| 174 | |
| 175 | // Hoist the nulls.is_some() check out of the loop. LLVM does not always |
| 176 | // unswitch this loop on its own (the Utf8View body is large enough to |
| 177 | // exceed its cost-benefit threshold). |
| 178 | if let Some(nulls_ref) = nulls.as_ref() { |
| 179 | for i in 0..len { |
| 180 | if nulls_ref.is_null(i) { |
| 181 | builder.append_placeholder(); |
| 182 | continue; |
| 183 | } |
| 184 | // SAFETY: union of input nulls is non-null at i, so each input is too. |
| 185 | let string = unsafe { string_array.value_unchecked(i) }; |
| 186 | let from = unsafe { from_array.value_unchecked(i) }; |
| 187 | let to = unsafe { to_array.value_unchecked(i) }; |
| 188 | apply_replace(&mut builder, string, from, to); |
| 189 | } |
| 190 | } else { |
| 191 | for i in 0..len { |
| 192 | // SAFETY: i < len, and no input has a null buffer. |
| 193 | let string = unsafe { string_array.value_unchecked(i) }; |
| 194 | let from = unsafe { from_array.value_unchecked(i) }; |
| 195 | let to = unsafe { to_array.value_unchecked(i) }; |
| 196 | apply_replace(&mut builder, string, from, to); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | Ok(Arc::new(builder.finish(nulls)?) as ArrayRef) |
| 201 | } |
| 202 | |
| 203 | /// Replaces all occurrences in string of substring from with substring to. |
| 204 | /// replace('abcdefabcdef', 'cd', 'XX') = 'abXXefabXXef' |
nothing calls this directly
no test coverage detected
searching dependent graphs…