mirror of
https://github.com/apple/pkl.git
synced 2026-01-13 15:13:38 +01:00
[PR #924] [CLOSED] [RFC] Add properties to List for byte-based encodings/hashes
#808
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/924
Author: @HT154
Created: 2/2/2025
Status: ❌ Closed
Base:
main← Head:list-byte-properties📝 Commits (1)
3821909Add properties toListfor byte-based encodings/hashes📊 Changes
5 files changed (+98 additions, -3 deletions)
View changed files
📝
pkl-core/src/main/java/org/pkl/core/runtime/VmList.java(+10 -1)📝
pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java(+8 -0)📝
pkl-core/src/main/java/org/pkl/core/stdlib/base/ListNodes.java(+42 -1)📝
pkl-core/src/main/resources/org/pkl/core/errorMessages.properties(+3 -0)📝
stdlib/base.pkl(+35 -1)📄 Description
The primary motivation here is to allow Pkl to properly work with arbitrary binary data. String can be abused to some extent, but because text encoding (and unicode normalization) is involved, what you see isn't what you get:
I'm most focused on
base64here, but I don't see an reason to omit the hashes either.This can actually be implemented in-langage, but it's far from performant:
Here's a test encoding a 16kB buffer:
And here's the exact same evaluation switched to use the
List.base64property introduced in this PR:This is roughly a 12x speedup!
Methods on generic types that only work for some type arguments don't really exist in Pkl yet. I considered an entirely separate stdlib class (possibly even a
Listsubclass?) that forces the element type toUInt8I'm interested in hearing thoughts on how to best approach this, but this was the most expedient path to prove the concept.As for why I'm doing this at all, here's a teaser:

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.