Stdlib index
- Captured-borrow migration worklist (3.3.3)
- Owned-bind migration worklist (8.2.7)
- Return-side title audit — the ride-through enumeration
- stdlib ownership audit
- stdlib ownership dispositions (plan 1.3.1 / 4.3.1)
aot
codec
codec / csv
codec / json
collection
- ArrayList
- BPlusTree
- Cache
- Collectors
- HashMap
- HashSet
- Heap
- ImmutableList
- ImmutableMap
- ImmutableSet
- LinkedList
- RedBlackTree
- Sort
collection / ltm
concurrent
error
- Exception
- NoOptionalValueException
- NotProvidedException
- RecoverableException
- ScopedBuildFailedException
- ScopeNotActiveException
- Throwable
- UnrecoverableException
gfx
hash
ifx
io
io / file
io / net
io / net / dns
io / net / uri
lang
lang / stream
math
math / fft
math / linalg
math / npio
math / poly
math / random
math / stats
nucleo
- Columns — the Arrow-laid-out substrate
- Fused tensor expressions — Fuse
- Table — the lazy, typed dataframe
- Tape — define-by-run autograd
- Transform intrinsics — Grad, Vmap, Jit
process
reflect
search / distance
search / fuzzy
search / ngram
session
time
- Clock
- DateTimeFormatter
- Duration
- Instant
- LocalDate
- LocalDateTime
- LocalTime
- Period
- ZonedDateTime
- ZoneId
- ZoneOffset
wire
xpu
xpu / mesh
StringBuilder
cajeta.lang.StringBuilder — growable UTF-8 byte buffer for building a
String in amortized O(N). Repeated s = s + chunk on an immutable String
is O(N²) (every + copies the whole accumulator); accumulate into a
StringBuilder instead and materialize once with toString(). The first 64
bytes live in an inline buffer embedded in the object, so a
stack StringBuilder() build of ≤ 64 bytes does zero heap allocation during
the build; a build that exceeds 64 bytes spills once to a doubling heap buffer
and continues with byte-identical output.
StringBuilder sb = stack StringBuilder();
sb.append("Hello, ");
sb.append("world");
String s #= sb.toString(); // "Hello, world"
Methods
| Signature | |
|---|---|
StringBuilder() ⚑ | Create an empty builder; no heap allocation until the build exceeds 64 bytes |
int32 count() | Number of UTF-8 bytes accumulated so far |
boolean isEmpty() | true when nothing has been appended yet |
void append(String s) | Append the UTF-8 bytes of s |
void appendBytes(int8[] src, int32 off, int32 len) | Append len bytes from src starting at off |
#String toString() | Materialize the accumulated bytes into a fresh owned String (one final copy of exactly count() bytes) |
⚑ = @EntryPoint
See also
- Source:
runtime/src/cajeta/lang/StringBuilder.cajeta - String — the immutable result type