mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-04-30 12:00:39 +00:00
8c7017a99d
- Update obioptions.Version from "Release 4.4.29" to "/v/ Release v5" - Update version.txt from 4.29 → .30 (automated by Makefile)
1.5 KiB
1.5 KiB
InPlaceToLower Function — Semantic Description
The obiutils.InPlaceToLower function provides a high-performance, memory-efficient utility for converting ASCII uppercase letters to lowercase in place, without allocating new data structures.
Core Functionality
- Takes a
[]byteslice (data) as input. - Iterates over each byte, identifying uppercase ASCII characters (i.e.,
'A'–'Z', values65–90). - Converts each uppercase byte to its lowercase counterpart using a bitwise OR with
32, leveraging the ASCII encoding property:
lowercase = uppercase | 0b0010_0000(since'a' - 'A' = 32). - Returns the same
[]byteslice, now mutated in-place.
Key Characteristics
- ✅ Zero-copy: No new memory is allocated—ideal for performance-critical or low-level contexts (e.g., streaming, embedded systems).
- ✅ ASCII-safe: Only modifies bytes in the
'A'–'Z'range; other bytes (e.g., digits, symbols, non-ASCII) remain unchanged. - ✅ Idiomatic Go: Uses idioms like
rangewith index/value and bitwise optimization. - ⚠️ Destructive: Input data is permanently modified—callers must clone if preservation is needed.
Use Cases
- Preprocessing raw HTTP headers or payloads.
- Optimizing case-insensitive comparisons in high-throughput systems.
- Embedded tools where GC pressure or heap allocation must be minimized.
Example
buf := []byte("HTTP/1.1 200 OK")
InPlaceToLower(buf) // buf is now []byte("http/1.1 200 ok")