(vec vector.Any, from, to int, base1 bool)
| 143 | } |
| 144 | |
| 145 | func (s *sliceExpr) evalStringOrBytesFast(vec vector.Any, from, to int, base1 bool) (vector.Any, bool) { |
| 146 | switch vec := vec.(type) { |
| 147 | case *vector.Const: |
| 148 | slice := s.bytesAt(vec, 0) |
| 149 | id := vec.Type().ID() |
| 150 | size := lengthOfBytesOrString(id, slice) |
| 151 | start, end := 0, size |
| 152 | if s.fromEval != nil { |
| 153 | start = sliceIndex(from, size, base1) |
| 154 | } |
| 155 | if s.toEval != nil { |
| 156 | end = sliceIndex(to, size, base1) |
| 157 | } |
| 158 | start, end = expr.FixSliceBounds(start, end, size) |
| 159 | slice = sliceBytesOrString(slice, id, start, end) |
| 160 | if id == super.IDBytes { |
| 161 | return vector.NewConstBytes(slice, vec.Len()), true |
| 162 | } |
| 163 | return vector.NewConstString(string(slice), vec.Len()), true |
| 164 | case *vector.View: |
| 165 | out, ok := s.evalStringOrBytesFast(vec.Any, from, to, base1) |
| 166 | if !ok { |
| 167 | return nil, false |
| 168 | } |
| 169 | return vector.NewView(out, vec.Index), true |
| 170 | case *vector.Dict: |
| 171 | out, ok := s.evalStringOrBytesFast(vec.Any, from, to, base1) |
| 172 | if !ok { |
| 173 | return nil, false |
| 174 | } |
| 175 | return vector.NewDict(out, vec.Index, vec.Counts), true |
| 176 | default: |
| 177 | offsets, bytes := stringOrBytesContents(vec) |
| 178 | newOffsets := []uint32{0} |
| 179 | newBytes := []byte{} |
| 180 | id := vec.Type().ID() |
| 181 | for i := range vec.Len() { |
| 182 | slice := bytes[offsets[i]:offsets[i+1]] |
| 183 | size := lengthOfBytesOrString(id, slice) |
| 184 | start, end := 0, size |
| 185 | if s.fromEval != nil { |
| 186 | start = sliceIndex(from, size, base1) |
| 187 | } |
| 188 | if s.toEval != nil { |
| 189 | end = sliceIndex(to, size, base1) |
| 190 | } |
| 191 | start, end = expr.FixSliceBounds(start, end, size) |
| 192 | slice = sliceBytesOrString(slice, id, start, end) |
| 193 | newBytes = append(newBytes, slice...) |
| 194 | newOffsets = append(newOffsets, newOffsets[len(newOffsets)-1]+uint32(len(slice))) |
| 195 | } |
| 196 | return s.bytesOrStringVec(vec.Type(), newOffsets, newBytes), true |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | func (s *sliceExpr) bytesOrStringVec(typ super.Type, offsets []uint32, bytes []byte) vector.Any { |
| 201 | switch typ.ID() { |
no test coverage detected