merge ws/perf-core
This commit is contained in:
commit
de755ca036
37 files changed
+5317
-2562
No files matched your search
+896
-283
File diff suppressed because it is too large.
Load diff
+608
-608
File diff suppressed because it is too large.
Load diff
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"Core_1": [[8, "src/Rosetta/init.luau"], [852, "src/Rosetta/Registry.luau"], [3261, "src/Rosetta/Types.luau"], [4344, "src/Rosetta/codecs/audio/Adpcm/init.luau"], [5098, "src/Rosetta/codecs/image/Yuv.luau"], [5366, "src/Rosetta/codecs/model/Rbx/init.luau"], [5603, "src/Rosetta/codecs/video/Video/init.luau"], [6160, "src/Rosetta/containers/AudioWrap.luau"], [6663, "src/Rosetta/containers/Ogg/Mux.luau"], [6858, "src/Rosetta/containers/Ogg/Page.luau"], [7027, "src/Rosetta/core/Bytes.luau"], [7554, "src/Rosetta/core/Crc32.luau"], [7666, "src/Rosetta/core/Err.luau"], [7748, "src/Rosetta/core/Input.luau"], [7824, "src/Rosetta/host/init.luau"]],
|
||||
"Core_1": [[8, "src/Rosetta/init.luau"], [888, "src/Rosetta/Registry.luau"], [3297, "src/Rosetta/Types.luau"], [4410, "src/Rosetta/codecs/audio/Adpcm/init.luau"], [5164, "src/Rosetta/codecs/image/Yuv.luau"], [5432, "src/Rosetta/codecs/model/Rbx/init.luau"], [5669, "src/Rosetta/codecs/video/Video/init.luau"], [6226, "src/Rosetta/containers/AudioWrap.luau"], [6729, "src/Rosetta/containers/Ogg/Mux.luau"], [6918, "src/Rosetta/core/Bytes.luau"], [7445, "src/Rosetta/core/Crc32.luau"], [7596, "src/Rosetta/core/Err.luau"], [7678, "src/Rosetta/core/Input.luau"], [7754, "src/Rosetta/host/init.luau"]],
|
||||
"Core_2": [[8, "src/Rosetta/ops/ImageOps/init.luau"], [656, "src/Rosetta/ops/ImageOps/Kernels.luau"]],
|
||||
"Mpeg2": [[8, "src/Rosetta/codecs/video/Dsp.luau"], [731, "src/Rosetta/codecs/video/Mpeg1/init.luau"], [743, "src/Rosetta/codecs/video/Mpeg2/init.luau"], [1110, "src/Rosetta/codecs/video/Mpeg2/Decoder.luau"], [2617, "src/Rosetta/codecs/video/Mpeg2/Tables.luau"], [2756, "src/Rosetta/codecs/video/Mpeg2/Vlc.luau"]],
|
||||
"H263": [[8, "src/Rosetta/codecs/video/H263/init.luau"], [164, "src/Rosetta/codecs/video/H263/Decoder.luau"], [1022, "src/Rosetta/codecs/video/H263/Tables.luau"]],
|
||||
@@ -12,10 +12,10 @@
|
||||
"Vp8": [[8, "src/Rosetta/codecs/image/Vp8/init.luau"], [138, "src/Rosetta/codecs/image/Vp8/Decode.luau"], [2094, "src/Rosetta/codecs/image/Vp8/Predict.luau"], [2353, "src/Rosetta/codecs/image/Vp8/Tables.luau"], [2602, "src/Rosetta/codecs/image/Vp8/Yuv.luau"], [2744, "src/Rosetta/codecs/image/Vp8L/init.luau"], [2848, "src/Rosetta/codecs/image/Vp8L/Decode.luau"], [3788, "src/Rosetta/codecs/image/Vp8L/Encode.luau"]],
|
||||
"Bcn": [[8, "src/Rosetta/codecs/image/Bcn/init.luau"], [115, "src/Rosetta/codecs/image/Bcn/Decode.luau"], [599, "src/Rosetta/codecs/image/Bcn/Encode.luau"]],
|
||||
"Png": [[8, "src/Rosetta/image/png/init.luau"], [588, "src/Rosetta/image/png/Apng.luau"], [668, "src/Rosetta/image/png/Decode.luau"], [1041, "src/Rosetta/image/png/Encode.luau"]],
|
||||
"Deflate": [[8, "src/Rosetta/codecs/compress/Deflate/init.luau"], [334, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], [754, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"]],
|
||||
"Brotli": [[8, "src/Rosetta/codecs/compress/Brotli/init.luau"], [95, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], [1064, "src/Rosetta/codecs/compress/Brotli/Static.luau"]],
|
||||
"Lzma": [[8, "src/Rosetta/codecs/compress/Lzma/init.luau"], [548, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], [586, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], [1059, "src/Rosetta/codecs/compress/Lzma/Filters.luau"]],
|
||||
"Zstd": [[8, "src/Rosetta/codecs/compress/Zstd/init.luau"], [65, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], [1023, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"]],
|
||||
"Deflate": [[8, "src/Rosetta/codecs/compress/Deflate/init.luau"], [334, "src/Rosetta/codecs/compress/Deflate/Compress.luau"], [816, "src/Rosetta/codecs/compress/Deflate/Inflate.luau"]],
|
||||
"Brotli": [[8, "src/Rosetta/codecs/compress/Brotli/init.luau"], [95, "src/Rosetta/codecs/compress/Brotli/Decode.luau"], [1071, "src/Rosetta/codecs/compress/Brotli/Static.luau"]],
|
||||
"Lzma": [[8, "src/Rosetta/codecs/compress/Lzma/init.luau"], [548, "src/Rosetta/codecs/compress/Lzma/Crc64.luau"], [615, "src/Rosetta/codecs/compress/Lzma/Decode.luau"], [1088, "src/Rosetta/codecs/compress/Lzma/Filters.luau"]],
|
||||
"Zstd": [[8, "src/Rosetta/codecs/compress/Zstd/init.luau"], [65, "src/Rosetta/codecs/compress/Zstd/Decode.luau"], [1049, "src/Rosetta/codecs/compress/Zstd/Xxh64.luau"]],
|
||||
"Mpa": [[8, "src/Rosetta/codecs/audio/Mpa/init.luau"], [22, "src/Rosetta/codecs/audio/Mpa/Analysis.luau"], [81, "src/Rosetta/codecs/audio/Mpa/Core.luau"], [1684, "src/Rosetta/codecs/audio/Mpa/EncTables.luau"], [1976, "src/Rosetta/codecs/audio/Mpa/Encode2.luau"], [2361, "src/Rosetta/codecs/audio/Mpa/Encode3.luau"], [3002, "src/Rosetta/codecs/audio/Mpa/Header.luau"], [3143, "src/Rosetta/codecs/audio/Mpa/Tables.luau"]],
|
||||
"Opus": [[8, "src/Rosetta/codecs/audio/Opus/init.luau"], [22, "src/Rosetta/codecs/audio/Opus/Celt.luau"], [1869, "src/Rosetta/codecs/audio/Opus/CeltEncoder.luau"], [2934, "src/Rosetta/codecs/audio/Opus/CeltTables.luau"], [2994, "src/Rosetta/codecs/audio/Opus/Decoder.luau"], [3454, "src/Rosetta/codecs/audio/Opus/Mdct.luau"], [3791, "src/Rosetta/codecs/audio/Opus/Packet.luau"], [4024, "src/Rosetta/codecs/audio/Opus/Silk.luau"], [6060, "src/Rosetta/codecs/audio/Opus/SilkTables.luau"]],
|
||||
"Vorbis": [[8, "src/Rosetta/codecs/audio/Vorbis/init.luau"], [21, "src/Rosetta/codecs/audio/Vorbis/Codebook.luau"], [405, "src/Rosetta/codecs/audio/Vorbis/Packet.luau"], [971, "src/Rosetta/codecs/audio/Vorbis/Setup.luau"], [1392, "src/Rosetta/codecs/audio/Vorbis/Tables.luau"]],
|
||||
@@ -32,15 +32,15 @@
|
||||
"audio": [[8, "src/Rosetta/audio/aac/init.luau"], [214, "src/Rosetta/audio/ac3/init.luau"], [360, "src/Rosetta/audio/adpcm/init.luau"], [505, "src/Rosetta/audio/adx/init.luau"], [736, "src/Rosetta/audio/aiff/init.luau"], [1127, "src/Rosetta/audio/ape/init.luau"], [1255, "src/Rosetta/audio/au/init.luau"], [1416, "src/Rosetta/audio/brstm/init.luau"], [1707, "src/Rosetta/audio/caf/init.luau"], [2369, "src/Rosetta/audio/flac/init.luau"], [2517, "src/Rosetta/audio/flac/Meta.luau"], [2739, "src/Rosetta/audio/flac/Stream.luau"], [3109, "src/Rosetta/audio/m4a/init.luau"], [3443, "src/Rosetta/audio/mp3/init.luau"], [3703, "src/Rosetta/audio/mp3/Index.luau"], [3894, "src/Rosetta/audio/mp3/Stream.luau"], [4121, "src/Rosetta/audio/mp3/Tags.luau"], [4433, "src/Rosetta/audio/mpc/init.luau"], [4527, "src/Rosetta/audio/opus/init.luau"], [4905, "src/Rosetta/audio/opus/Encode.luau"], [5016, "src/Rosetta/audio/qoa/init.luau"], [5196, "src/Rosetta/audio/tta/init.luau"], [5314, "src/Rosetta/audio/vag/init.luau"], [5537, "src/Rosetta/audio/voc/init.luau"], [5812, "src/Rosetta/audio/vorbis/init.luau"], [6266, "src/Rosetta/audio/vorbis/Encode.luau"], [7079, "src/Rosetta/audio/wav/init.luau"], [7700, "src/Rosetta/audio/wav/Codecs.luau"], [7866, "src/Rosetta/audio/wavpack/init.luau"]],
|
||||
"cad": [[8, "src/Rosetta/cad/step/init.luau"], [390, "src/Rosetta/cad/step/Brep.luau"], [625, "src/Rosetta/cad/step/Parse.luau"], [1182, "src/Rosetta/cad/step/Write.luau"]],
|
||||
"codecs_audio": [[8, "src/Rosetta/codecs/audio/Ac3/init.luau"], [167, "src/Rosetta/codecs/audio/Ac3/Decode.luau"], [1052, "src/Rosetta/codecs/audio/Ac3/Tables.luau"], [1153, "src/Rosetta/codecs/audio/Adpcm/Decoder.luau"], [1455, "src/Rosetta/codecs/audio/Alac/init.luau"], [1689, "src/Rosetta/codecs/audio/Alac/Decode.luau"], [2108, "src/Rosetta/codecs/audio/Alac/Encode.luau"], [2520, "src/Rosetta/codecs/audio/Ape/init.luau"], [2735, "src/Rosetta/codecs/audio/Ape/Decode.luau"], [3496, "src/Rosetta/codecs/audio/ApeTag.luau"], [3593, "src/Rosetta/codecs/audio/Mdct/init.luau"], [3777, "src/Rosetta/codecs/audio/Mdct/Fft.luau"], [3986, "src/Rosetta/codecs/audio/MidiRender.luau"], [4332, "src/Rosetta/codecs/audio/Pcm/init.luau"], [4595, "src/Rosetta/codecs/audio/Pcm/Convert.luau"], [4892, "src/Rosetta/codecs/audio/Qoa/init.luau"], [5174, "src/Rosetta/codecs/audio/Resample/init.luau"], [5533, "src/Rosetta/codecs/audio/Stream.luau"], [5694, "src/Rosetta/codecs/audio/Tta/init.luau"], [5811, "src/Rosetta/codecs/audio/Tta/Decode.luau"], [6063, "src/Rosetta/codecs/audio/VorbisComment.luau"]],
|
||||
"codecs_compress": [[8, "src/Rosetta/codecs/compress/Bzip2/init.luau"], [56, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], [572, "src/Rosetta/codecs/compress/Explode.luau"], [768, "src/Rosetta/codecs/compress/Lz4.luau"], [1037, "src/Rosetta/codecs/compress/Lzh/init.luau"], [1641, "src/Rosetta/codecs/compress/Lzw/init.luau"], [1909, "src/Rosetta/codecs/compress/Lzx.luau"], [2343, "src/Rosetta/codecs/compress/PackBits.luau"], [2433, "src/Rosetta/codecs/compress/Quantum.luau"], [2670, "src/Rosetta/codecs/compress/UnixCompress.luau"], [2974, "src/Rosetta/codecs/compress/Xxh32.luau"]],
|
||||
"codecs_entropy": [[8, "src/Rosetta/codecs/entropy/Huffman.luau"], [290, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], [301, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], [515, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"]],
|
||||
"codecs_compress": [[8, "src/Rosetta/codecs/compress/Bzip2/init.luau"], [52, "src/Rosetta/codecs/compress/Bzip2/Decode.luau"], [565, "src/Rosetta/codecs/compress/Explode.luau"], [761, "src/Rosetta/codecs/compress/Lz4.luau"], [1030, "src/Rosetta/codecs/compress/Lzh/init.luau"], [1634, "src/Rosetta/codecs/compress/Lzw/init.luau"], [1902, "src/Rosetta/codecs/compress/Lzx.luau"], [2336, "src/Rosetta/codecs/compress/PackBits.luau"], [2426, "src/Rosetta/codecs/compress/Quantum.luau"], [2663, "src/Rosetta/codecs/compress/UnixCompress.luau"], [2967, "src/Rosetta/codecs/compress/Xxh32.luau"]],
|
||||
"codecs_entropy": [[8, "src/Rosetta/codecs/entropy/Huffman.luau"], [295, "src/Rosetta/codecs/entropy/RangeCoder/init.luau"], [306, "src/Rosetta/codecs/entropy/RangeCoder/Decoder.luau"], [520, "src/Rosetta/codecs/entropy/RangeCoder/Encoder.luau"]],
|
||||
"codecs_font": [[8, "src/Rosetta/codecs/font/Bitmap.luau"], [209, "src/Rosetta/codecs/font/Cff/init.luau"], [850, "src/Rosetta/codecs/font/GlyphNames.luau"], [1000, "src/Rosetta/codecs/font/TrueType/init.luau"], [1314, "src/Rosetta/codecs/font/TrueType/Glyf.luau"], [1706, "src/Rosetta/codecs/font/TrueType/Tables.luau"]],
|
||||
"codecs_image": [[8, "src/Rosetta/codecs/image/Blend.luau"], [387, "src/Rosetta/codecs/image/Etc.luau"], [685, "src/Rosetta/codecs/image/Half.luau"], [754, "src/Rosetta/codecs/image/Miptex.luau"], [1054, "src/Rosetta/codecs/image/Pixels.luau"], [1374, "src/Rosetta/codecs/image/Quantize/init.luau"], [1835, "src/Rosetta/codecs/image/Raster.luau"], [2532, "src/Rosetta/codecs/image/Texel.luau"], [2905, "src/Rosetta/codecs/image/Texture.luau"]],
|
||||
"codecs_model": [[8, "src/Rosetta/codecs/model/Brush.luau"], [648, "src/Rosetta/codecs/model/Displacement.luau"], [797, "src/Rosetta/codecs/model/DoomMap/init.luau"], [1242, "src/Rosetta/codecs/model/DoomMap/Udmf.luau"], [1492, "src/Rosetta/codecs/model/Mat4.luau"], [1751, "src/Rosetta/codecs/model/MeshFlatten.luau"], [2279, "src/Rosetta/codecs/model/Minecraft/init.luau"], [2831, "src/Rosetta/codecs/model/Minecraft/Colors.luau"], [2910, "src/Rosetta/codecs/model/Minecraft/Legacy.luau"], [3017, "src/Rosetta/codecs/model/Minecraft/Packed.luau"], [3223, "src/Rosetta/codecs/model/Patch.luau"], [3347, "src/Rosetta/codecs/model/Polygon.luau"], [3581, "src/Rosetta/codecs/model/Rbx/Binary.luau"], [4335, "src/Rosetta/codecs/model/Rig.luau"], [4578, "src/Rosetta/codecs/model/Sampler.luau"], [4738, "src/Rosetta/codecs/model/SourceAnim.luau"], [4959, "src/Rosetta/codecs/model/Vrml/init.luau"], [5107, "src/Rosetta/codecs/model/Vrml/Build.luau"], [5681, "src/Rosetta/codecs/model/Vrml/Fields.luau"], [5844, "src/Rosetta/codecs/model/Vrml/Geometry.luau"], [6593, "src/Rosetta/codecs/model/Vrml/Parse.luau"], [7115, "src/Rosetta/codecs/model/Vrml/Write.luau"], [7842, "src/Rosetta/codecs/model/Vrml/Xml.luau"]],
|
||||
"codecs_text": [[8, "src/Rosetta/codecs/text/GodotVariant.luau"], [667, "src/Rosetta/codecs/text/Json/init.luau"], [936, "src/Rosetta/codecs/text/Json/Decode.luau"], [1350, "src/Rosetta/codecs/text/Json/Encode.luau"], [1652, "src/Rosetta/codecs/text/KeyValues/init.luau"], [2222, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], [2528, "src/Rosetta/codecs/text/Lexer/init.luau"], [2660, "src/Rosetta/codecs/text/Nbt/init.luau"], [3013, "src/Rosetta/codecs/text/Nbt/Binary.luau"], [3705, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], [4345, "src/Rosetta/codecs/text/Nbt/Value.luau"], [4583, "src/Rosetta/codecs/text/Text/init.luau"], [4674, "src/Rosetta/codecs/text/Url/init.luau"], [4879, "src/Rosetta/codecs/text/Xml/init.luau"], [5282, "src/Rosetta/codecs/text/Xml/Parse.luau"]],
|
||||
"codecs_text": [[8, "src/Rosetta/codecs/text/GodotVariant.luau"], [667, "src/Rosetta/codecs/text/Json/init.luau"], [936, "src/Rosetta/codecs/text/Json/Decode.luau"], [1371, "src/Rosetta/codecs/text/Json/Encode.luau"], [1716, "src/Rosetta/codecs/text/KeyValues/init.luau"], [2286, "src/Rosetta/codecs/text/KeyValues/Binary.luau"], [2592, "src/Rosetta/codecs/text/Lexer/init.luau"], [2724, "src/Rosetta/codecs/text/Nbt/init.luau"], [3077, "src/Rosetta/codecs/text/Nbt/Binary.luau"], [3769, "src/Rosetta/codecs/text/Nbt/Snbt.luau"], [4409, "src/Rosetta/codecs/text/Nbt/Value.luau"], [4647, "src/Rosetta/codecs/text/Text/init.luau"], [4738, "src/Rosetta/codecs/text/Url/init.luau"], [4943, "src/Rosetta/codecs/text/Xml/init.luau"], [5393, "src/Rosetta/codecs/text/Xml/Parse.luau"]],
|
||||
"codecs_video": [[8, "src/Rosetta/codecs/video/Video/Source.luau"]],
|
||||
"containers": [[8, "src/Rosetta/containers/Archive.luau"], [275, "src/Rosetta/containers/Avi/init.luau"], [827, "src/Rosetta/containers/Blend.luau"], [1566, "src/Rosetta/containers/Chunks.luau"], [1701, "src/Rosetta/containers/Cpio.luau"], [2129, "src/Rosetta/containers/Demux.luau"], [2404, "src/Rosetta/containers/Ebml/init.luau"], [2717, "src/Rosetta/containers/Fat.luau"], [3405, "src/Rosetta/containers/Iso9660.luau"], [3910, "src/Rosetta/containers/IsoBmff/init.luau"], [4080, "src/Rosetta/containers/IsoBmff/Box.luau"], [4268, "src/Rosetta/containers/IsoBmff/Demux.luau"], [5113, "src/Rosetta/containers/IsoBmff/Meta.luau"], [5634, "src/Rosetta/containers/IsoBmff/Mux.luau"], [6150, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], [6267, "src/Rosetta/containers/MacFile.luau"], [6416, "src/Rosetta/containers/Ogg/init.luau"], [6841, "src/Rosetta/containers/Riff/init.luau"], [7158, "src/Rosetta/containers/Tar.luau"], [7572, "src/Rosetta/containers/Zip/init.luau"]],
|
||||
"core": [[8, "src/Rosetta/core/Adler32.luau"], [54, "src/Rosetta/core/Base64.luau"], [213, "src/Rosetta/core/Bits.luau"], [506, "src/Rosetta/core/Crc16.luau"], [558, "src/Rosetta/core/Md5.luau"], [717, "src/Rosetta/core/Sniff.luau"]],
|
||||
"containers": [[8, "src/Rosetta/containers/Archive.luau"], [275, "src/Rosetta/containers/Avi/init.luau"], [827, "src/Rosetta/containers/Blend.luau"], [1566, "src/Rosetta/containers/Chunks.luau"], [1701, "src/Rosetta/containers/Cpio.luau"], [2129, "src/Rosetta/containers/Demux.luau"], [2404, "src/Rosetta/containers/Ebml/init.luau"], [2717, "src/Rosetta/containers/Fat.luau"], [3405, "src/Rosetta/containers/Iso9660.luau"], [3910, "src/Rosetta/containers/IsoBmff/init.luau"], [4080, "src/Rosetta/containers/IsoBmff/Box.luau"], [4268, "src/Rosetta/containers/IsoBmff/Demux.luau"], [5113, "src/Rosetta/containers/IsoBmff/Meta.luau"], [5634, "src/Rosetta/containers/IsoBmff/Mux.luau"], [6150, "src/Rosetta/containers/IsoBmff/QtPalette.luau"], [6267, "src/Rosetta/containers/MacFile.luau"], [6416, "src/Rosetta/containers/Ogg/init.luau"], [6841, "src/Rosetta/containers/Ogg/Page.luau"], [7007, "src/Rosetta/containers/Riff/init.luau"], [7324, "src/Rosetta/containers/Tar.luau"], [7738, "src/Rosetta/containers/Zip/init.luau"]],
|
||||
"core": [[8, "src/Rosetta/core/Adler32.luau"], [68, "src/Rosetta/core/Base64.luau"], [296, "src/Rosetta/core/Bits.luau"], [589, "src/Rosetta/core/Crc16.luau"], [641, "src/Rosetta/core/Md5.luau"], [799, "src/Rosetta/core/Sniff.luau"]],
|
||||
"data": [[8, "src/Rosetta/data/cbor/init.luau"], [107, "src/Rosetta/data/cbor/Codec.luau"], [676, "src/Rosetta/data/csv/init.luau"], [988, "src/Rosetta/data/ini/init.luau"], [1234, "src/Rosetta/data/json/init.luau"], [1326, "src/Rosetta/data/msgpack/init.luau"], [1415, "src/Rosetta/data/msgpack/Codec.luau"], [1857, "src/Rosetta/data/nbt/init.luau"], [1916, "src/Rosetta/data/plist/init.luau"], [2222, "src/Rosetta/data/plist/Binary.luau"], [2489, "src/Rosetta/data/q3shader/init.luau"], [2728, "src/Rosetta/data/q3skin/init.luau"], [2824, "src/Rosetta/data/snbt/init.luau"], [2887, "src/Rosetta/data/toml/init.luau"], [2954, "src/Rosetta/data/toml/Decode.luau"], [3582, "src/Rosetta/data/toml/Encode.luau"], [3791, "src/Rosetta/data/tres/init.luau"], [3936, "src/Rosetta/data/vdf/init.luau"], [4037, "src/Rosetta/data/xml/init.luau"], [4093, "src/Rosetta/data/yaml/init.luau"], [4166, "src/Rosetta/data/yaml/Emit.luau"], [4456, "src/Rosetta/data/yaml/Parse.luau"]],
|
||||
"font": [[8, "src/Rosetta/font/bdf/init.luau"], [297, "src/Rosetta/font/bmfont/init.luau"], [724, "src/Rosetta/font/bmfont/Parse.luau"], [1177, "src/Rosetta/font/eot/init.luau"], [1409, "src/Rosetta/font/fon/init.luau"], [1692, "src/Rosetta/font/hershey/init.luau"], [1887, "src/Rosetta/font/pcf/init.luau"], [2167, "src/Rosetta/font/psf/init.luau"], [2487, "src/Rosetta/font/ttf/init.luau"], [2538, "src/Rosetta/font/type1/init.luau"], [2897, "src/Rosetta/font/type1/Charstring.luau"], [3175, "src/Rosetta/font/woff/init.luau"], [3307, "src/Rosetta/font/woff2/init.luau"], [3364, "src/Rosetta/font/woff2/Rebuild.luau"]],
|
||||
"host": [[8, "src/Rosetta/host/Love.luau"], [151, "src/Rosetta/host/LuaJIT.luau"], [201, "src/Rosetta/host/Luau.luau"], [224, "src/Rosetta/host/Roblox.luau"]],
|
||||
@@ -50,14 +50,14 @@
|
||||
"model_1": [[8, "src/Rosetta/model/3ds/init.luau"], [91, "src/Rosetta/model/3ds/Build.luau"], [738, "src/Rosetta/model/3ds/Read.luau"], [1234, "src/Rosetta/model/3ds/Write.luau"], [2039, "src/Rosetta/model/3mf/init.luau"], [2121, "src/Rosetta/model/3mf/Read.luau"], [2709, "src/Rosetta/model/3mf/Write.luau"], [3114, "src/Rosetta/model/ase/init.luau"], [3237, "src/Rosetta/model/ase/Build.luau"], [3811, "src/Rosetta/model/ase/Parse.luau"], [3880, "src/Rosetta/model/ase/Write.luau"], [4343, "src/Rosetta/model/b3d/init.luau"], [4398, "src/Rosetta/model/b3d/Read.luau"], [4969, "src/Rosetta/model/blend/init.luau"], [5065, "src/Rosetta/model/blend/Anim.luau"], [5411, "src/Rosetta/model/blend/Material.luau"], [5763, "src/Rosetta/model/blend/Mesh.luau"], [6398, "src/Rosetta/model/blend/Normals.luau"], [6559, "src/Rosetta/model/blend/Prim.luau"]],
|
||||
"model_2": [[8, "src/Rosetta/model/blend/Read.luau"], [908, "src/Rosetta/model/bsp/init.luau"], [1099, "src/Rosetta/model/bsp/Lightmap.luau"], [1165, "src/Rosetta/model/bsp/Quake.luau"], [1554, "src/Rosetta/model/bsp/Quake3.luau"], [1783, "src/Rosetta/model/bsp/Tree.luau"], [2171, "src/Rosetta/model/buildmap/init.luau"], [2443, "src/Rosetta/model/buildmap/Geometry.luau"], [2846, "src/Rosetta/model/d3map/init.luau"], [3128, "src/Rosetta/model/d3map/Parse.luau"], [3326, "src/Rosetta/model/dae/init.luau"], [3515, "src/Rosetta/model/dae/Math.luau"], [3562, "src/Rosetta/model/dae/Read.luau"], [5412, "src/Rosetta/model/dae/Write.luau"], [5781, "src/Rosetta/model/fbx/init.luau"], [5929, "src/Rosetta/model/fbx/Ascii.luau"], [6199, "src/Rosetta/model/fbx/Binary.luau"]],
|
||||
"model_3": [[8, "src/Rosetta/model/fbx/Read.luau"], [1370, "src/Rosetta/model/fbx/Write.luau"], [2355, "src/Rosetta/model/fbx/Xform.luau"], [2396, "src/Rosetta/model/gltf/init.luau"], [2633, "src/Rosetta/model/gltf/Pack.luau"], [2702, "src/Rosetta/model/gltf/Read.luau"], [3433, "src/Rosetta/model/gltf/Write.luau"], [4113, "src/Rosetta/model/godot/init.luau"], [4204, "src/Rosetta/model/godot/Build.luau"], [4746, "src/Rosetta/model/godot/Primitives.luau"], [5021, "src/Rosetta/model/godot/Surface.luau"], [5506, "src/Rosetta/model/godot/Write.luau"], [5835, "src/Rosetta/model/iqm/init.luau"], [5911, "src/Rosetta/model/iqm/Read.luau"], [6266, "src/Rosetta/model/iqm/Write.luau"], [6953, "src/Rosetta/model/ldraw/init.luau"], [7031, "src/Rosetta/model/ldraw/Colors.luau"]],
|
||||
"model_4": [[8, "src/Rosetta/model/ldraw/Read.luau"], [585, "src/Rosetta/model/lwo/init.luau"], [661, "src/Rosetta/model/lwo/Build.luau"], [1123, "src/Rosetta/model/lwo/Parse.luau"], [1666, "src/Rosetta/model/map/init.luau"], [1983, "src/Rosetta/model/map/Build.luau"], [2227, "src/Rosetta/model/map/Parse.luau"], [2612, "src/Rosetta/model/map/Write.luau"], [2758, "src/Rosetta/model/mca/init.luau"], [3100, "src/Rosetta/model/mca/Chunk.luau"], [3233, "src/Rosetta/model/mca/Lz4Block.luau"], [3303, "src/Rosetta/model/md2/init.luau"], [3502, "src/Rosetta/model/md3/init.luau"], [3730, "src/Rosetta/model/md5/init.luau"], [3811, "src/Rosetta/model/md5/Read.luau"], [4244, "src/Rosetta/model/mdl/init.luau"], [4326, "src/Rosetta/model/mdl/HalfLife.luau"], [4630, "src/Rosetta/model/mdl/Quake.luau"], [4848, "src/Rosetta/model/ms3d/init.luau"], [4920, "src/Rosetta/model/ms3d/Read.luau"], [5366, "src/Rosetta/model/ms3d/Write.luau"], [5835, "src/Rosetta/model/obj/init.luau"], [6577, "src/Rosetta/model/obj/Mtl.luau"], [6864, "src/Rosetta/model/off/init.luau"]],
|
||||
"model_5": [[8, "src/Rosetta/model/ply/init.luau"], [1113, "src/Rosetta/model/ply/Binary.luau"], [1314, "src/Rosetta/model/pmx/init.luau"], [1383, "src/Rosetta/model/pmx/Build.luau"], [1679, "src/Rosetta/model/pmx/Pmd.luau"], [2014, "src/Rosetta/model/pmx/Read.luau"], [2418, "src/Rosetta/model/proc/init.luau"], [2800, "src/Rosetta/model/qb/init.luau"], [3193, "src/Rosetta/model/rbxm/init.luau"], [3785, "src/Rosetta/model/rbxmx/init.luau"], [4438, "src/Rosetta/model/robloxmesh/init.luau"], [5097, "src/Rosetta/model/robloxmesh/Parse.luau"], [5554, "src/Rosetta/model/robloxmesh/Write.luau"], [5663, "src/Rosetta/model/schematic/init.luau"], [5984, "src/Rosetta/model/schematic/Common.luau"], [6104, "src/Rosetta/model/schematic/Litematic.luau"], [6315, "src/Rosetta/model/schematic/Mcedit.luau"], [6559, "src/Rosetta/model/schematic/Sponge.luau"], [6688, "src/Rosetta/model/smd/init.luau"], [6755, "src/Rosetta/model/smd/Read.luau"], [7024, "src/Rosetta/model/smd/Write.luau"], [7267, "src/Rosetta/model/sourcemdl/init.luau"], [7438, "src/Rosetta/model/sourcemdl/Build.luau"], [7868, "src/Rosetta/model/sourcemdl/Material.luau"]],
|
||||
"model_4": [[8, "src/Rosetta/model/ldraw/Read.luau"], [585, "src/Rosetta/model/lwo/init.luau"], [661, "src/Rosetta/model/lwo/Build.luau"], [1123, "src/Rosetta/model/lwo/Parse.luau"], [1666, "src/Rosetta/model/map/init.luau"], [1983, "src/Rosetta/model/map/Build.luau"], [2227, "src/Rosetta/model/map/Parse.luau"], [2612, "src/Rosetta/model/map/Write.luau"], [2758, "src/Rosetta/model/mca/init.luau"], [3100, "src/Rosetta/model/mca/Chunk.luau"], [3233, "src/Rosetta/model/mca/Lz4Block.luau"], [3303, "src/Rosetta/model/md2/init.luau"], [3502, "src/Rosetta/model/md3/init.luau"], [3730, "src/Rosetta/model/md5/init.luau"], [3811, "src/Rosetta/model/md5/Read.luau"], [4244, "src/Rosetta/model/mdl/init.luau"], [4326, "src/Rosetta/model/mdl/HalfLife.luau"], [4630, "src/Rosetta/model/mdl/Quake.luau"], [4848, "src/Rosetta/model/ms3d/init.luau"], [4920, "src/Rosetta/model/ms3d/Read.luau"], [5366, "src/Rosetta/model/ms3d/Write.luau"], [5835, "src/Rosetta/model/obj/init.luau"], [6653, "src/Rosetta/model/obj/Mtl.luau"], [6941, "src/Rosetta/model/off/init.luau"]],
|
||||
"model_5": [[8, "src/Rosetta/model/ply/init.luau"], [1113, "src/Rosetta/model/ply/Binary.luau"], [1314, "src/Rosetta/model/pmx/init.luau"], [1383, "src/Rosetta/model/pmx/Build.luau"], [1679, "src/Rosetta/model/pmx/Pmd.luau"], [2014, "src/Rosetta/model/pmx/Read.luau"], [2418, "src/Rosetta/model/proc/init.luau"], [2800, "src/Rosetta/model/qb/init.luau"], [3193, "src/Rosetta/model/rbxm/init.luau"], [3786, "src/Rosetta/model/rbxmx/init.luau"], [4462, "src/Rosetta/model/robloxmesh/init.luau"], [5121, "src/Rosetta/model/robloxmesh/Parse.luau"], [5578, "src/Rosetta/model/robloxmesh/Write.luau"], [5687, "src/Rosetta/model/schematic/init.luau"], [6008, "src/Rosetta/model/schematic/Common.luau"], [6128, "src/Rosetta/model/schematic/Litematic.luau"], [6339, "src/Rosetta/model/schematic/Mcedit.luau"], [6583, "src/Rosetta/model/schematic/Sponge.luau"], [6712, "src/Rosetta/model/smd/init.luau"], [6779, "src/Rosetta/model/smd/Read.luau"], [7048, "src/Rosetta/model/smd/Write.luau"], [7291, "src/Rosetta/model/sourcemdl/init.luau"], [7462, "src/Rosetta/model/sourcemdl/Build.luau"], [7892, "src/Rosetta/model/sourcemdl/Material.luau"]],
|
||||
"model_6": [[8, "src/Rosetta/model/sourcemdl/Mdl.luau"], [535, "src/Rosetta/model/sourcemdl/Phy.luau"], [658, "src/Rosetta/model/sourcemdl/Vtx.luau"], [840, "src/Rosetta/model/sourcemdl/Vvd.luau"], [934, "src/Rosetta/model/stl/init.luau"], [1384, "src/Rosetta/model/stl/Decode.luau"], [1458, "src/Rosetta/model/t3d/init.luau"], [1552, "src/Rosetta/model/t3d/Build.luau"], [1957, "src/Rosetta/model/t3d/Parse.luau"], [2125, "src/Rosetta/model/udmf/init.luau"], [2208, "src/Rosetta/model/usda/init.luau"], [2417, "src/Rosetta/model/usda/Build.luau"], [3695, "src/Rosetta/model/usda/Parse.luau"], [4493, "src/Rosetta/model/usda/Write.luau"], [5310, "src/Rosetta/model/vbsp/init.luau"], [5756, "src/Rosetta/model/vbsp/Faces.luau"], [5980, "src/Rosetta/model/vbsp/Props.luau"], [6072, "src/Rosetta/model/vmf/init.luau"], [6397, "src/Rosetta/model/vmf/Build.luau"], [6821, "src/Rosetta/model/vox/init.luau"], [7707, "src/Rosetta/model/vox/Grid.luau"], [7764, "src/Rosetta/model/vrml/init.luau"], [7830, "src/Rosetta/model/x/init.luau"]],
|
||||
"model_7": [[8, "src/Rosetta/model/x/Build.luau"], [571, "src/Rosetta/model/x/Parse.luau"], [868, "src/Rosetta/model/x3d/init.luau"]],
|
||||
"music": [[8, "src/Rosetta/music/669/init.luau"], [214, "src/Rosetta/music/ahx/init.luau"], [265, "src/Rosetta/music/far/init.luau"], [494, "src/Rosetta/music/hmp/init.luau"], [758, "src/Rosetta/music/hvl/init.luau"], [809, "src/Rosetta/music/it/init.luau"], [1227, "src/Rosetta/music/it/Itsex.luau"], [1343, "src/Rosetta/music/med/init.luau"], [1990, "src/Rosetta/music/midi/init.luau"], [2133, "src/Rosetta/music/midi/Smf.luau"], [2544, "src/Rosetta/music/mod/init.luau"], [2897, "src/Rosetta/music/mtm/init.luau"], [3119, "src/Rosetta/music/mus/init.luau"], [3276, "src/Rosetta/music/okt/init.luau"], [3557, "src/Rosetta/music/ptm/init.luau"], [3779, "src/Rosetta/music/s3m/init.luau"], [4015, "src/Rosetta/music/sf2/init.luau"], [4058, "src/Rosetta/music/stm/init.luau"], [4289, "src/Rosetta/music/ult/init.luau"], [4593, "src/Rosetta/music/umx/init.luau"], [4809, "src/Rosetta/music/xm/init.luau"], [5370, "src/Rosetta/music/xmi/init.luau"]],
|
||||
"ops": [[8, "src/Rosetta/ops/AudioOps.luau"], [457, "src/Rosetta/ops/LayerOps.luau"], [550, "src/Rosetta/ops/MeshOps/init.luau"], [1586, "src/Rosetta/ops/MeshOps/Greedy.luau"], [1753, "src/Rosetta/ops/MusicOps.luau"]],
|
||||
"ops": [[8, "src/Rosetta/ops/AudioOps.luau"], [457, "src/Rosetta/ops/LayerOps.luau"], [550, "src/Rosetta/ops/MeshOps/init.luau"], [1602, "src/Rosetta/ops/MeshOps/Greedy.luau"], [1769, "src/Rosetta/ops/MusicOps.luau"]],
|
||||
"playlist": [[8, "src/Rosetta/playlist/m3u/init.luau"], [361, "src/Rosetta/playlist/pls/init.luau"], [539, "src/Rosetta/playlist/xspf/init.luau"]],
|
||||
"subtitle": [[8, "src/Rosetta/subtitle/ass/init.luau"], [452, "src/Rosetta/subtitle/srt/init.luau"], [625, "src/Rosetta/subtitle/vtt/init.luau"]],
|
||||
"vector": [[8, "src/Rosetta/vector/gamemaps/init.luau"], [195, "src/Rosetta/vector/gamemaps/Expand.luau"], [292, "src/Rosetta/vector/ldtk/init.luau"], [384, "src/Rosetta/vector/ldtk/Read.luau"], [720, "src/Rosetta/vector/ldtk/Write.luau"], [1368, "src/Rosetta/vector/ogmo/init.luau"], [1487, "src/Rosetta/vector/ogmo/Read.luau"], [1892, "src/Rosetta/vector/ogmo/Write.luau"], [2246, "src/Rosetta/vector/svg/init.luau"], [2332, "src/Rosetta/vector/svg/Parse.luau"], [3078, "src/Rosetta/vector/svg/PathData.luau"], [3446, "src/Rosetta/vector/svg/Render.luau"], [3863, "src/Rosetta/vector/svg/Style.luau"], [4235, "src/Rosetta/vector/svg/Write.luau"], [4435, "src/Rosetta/vector/tiled/init.luau"], [4615, "src/Rosetta/vector/tiled/Data.luau"], [4766, "src/Rosetta/vector/tiled/Tmj.luau"], [5397, "src/Rosetta/vector/tiled/Tmx.luau"]],
|
||||
"video": [[8, "src/Rosetta/video/avi/init.luau"], [302, "src/Rosetta/video/fli/init.luau"], [453, "src/Rosetta/video/flv/init.luau"], [837, "src/Rosetta/video/flv/Amf.luau"], [995, "src/Rosetta/video/flv/Mux.luau"], [1276, "src/Rosetta/video/h264/init.luau"], [1415, "src/Rosetta/video/mkv/init.luau"], [1571, "src/Rosetta/video/mkv/Mux.luau"], [1850, "src/Rosetta/video/mkv/Parse.luau"], [2571, "src/Rosetta/video/mp4/init.luau"], [2899, "src/Rosetta/video/mpegps/init.luau"], [3086, "src/Rosetta/video/mpegts/init.luau"], [3324, "src/Rosetta/video/ogv/init.luau"], [3719, "src/Rosetta/video/smk/init.luau"], [4028, "src/Rosetta/video/smk/Audio.luau"], [4148, "src/Rosetta/video/y4m/init.luau"]]
|
||||
"video": [[8, "src/Rosetta/video/avi/init.luau"], [302, "src/Rosetta/video/fli/init.luau"], [453, "src/Rosetta/video/flv/init.luau"], [837, "src/Rosetta/video/flv/Amf.luau"], [995, "src/Rosetta/video/flv/Mux.luau"], [1276, "src/Rosetta/video/h264/init.luau"], [1415, "src/Rosetta/video/mkv/init.luau"], [1571, "src/Rosetta/video/mkv/Mux.luau"], [1850, "src/Rosetta/video/mkv/Parse.luau"], [2571, "src/Rosetta/video/mp4/init.luau"], [2899, "src/Rosetta/video/mpegps/init.luau"], [3086, "src/Rosetta/video/mpegts/init.luau"], [3332, "src/Rosetta/video/ogv/init.luau"], [3727, "src/Rosetta/video/smk/init.luau"], [4036, "src/Rosetta/video/smk/Audio.luau"], [4156, "src/Rosetta/video/y4m/init.luau"]]
|
||||
}
|
||||
+1064
-451
File diff suppressed because it is too large.
Load diff
+928
-311
File diff suppressed because it is too large.
Load diff
+609
-609
File diff suppressed because it is too large.
Load diff
@@ -573,6 +573,10 @@ do
|
||||
if j < 0 then j = #s + j + 1 end
|
||||
local n = 0
|
||||
while i <= j do
|
||||
local h = string.find(s, "[\128-\255]", i)
|
||||
if not h or h > j then return n + j - i + 1 end
|
||||
n = n + h - i
|
||||
i = h
|
||||
local c, l = dec(s, i)
|
||||
if not c then return nil, i end
|
||||
n = n + 1
|
||||
|
||||
+43
-13
@@ -652,23 +652,47 @@ Types.null = table.freeze(setmetatable({}, nullMeta))
|
||||
-- Objects (maps) whose key order matters, and empty objects (which would otherwise read back as empty arrays), carry
|
||||
-- an "object" metatable with their key order. Decoders mark empty objects always and every object when asked
|
||||
-- (opts.ordered); encoders write an object's keys in that order (keys added later, or plain tables: sorted).
|
||||
local OBJECT = { __object = true }
|
||||
-- The key order is the __keys field of the object's own metatable, or (for a table that came with a metatable of its
|
||||
-- own) an entry in a weak map.
|
||||
local objectMeta: { [any]: { any } } = setmetatable({}, { __mode = "k" }) :: any -- object -> its key order
|
||||
local function orderOf(v: any): { any }?
|
||||
local mt: any = getmetatable(v)
|
||||
if type(mt) == "table" then
|
||||
local k: any = rawget(mt, "__keys")
|
||||
if k ~= nil then
|
||||
return k
|
||||
end
|
||||
end
|
||||
return objectMeta[v]
|
||||
end
|
||||
local NOKEYS: { any } = table.freeze({}) :: any
|
||||
function Types.object(t: { [any]: any }?, keys: { any }?): { [any]: any }
|
||||
local o: { [any]: any } = t or {}
|
||||
if getmetatable(o) == nil then
|
||||
setmetatable(o, OBJECT)
|
||||
local k: { any } = keys or NOKEYS
|
||||
local mt: any = getmetatable(o)
|
||||
if mt == nil or (type(mt) == "table" and rawget(mt, "__keys") ~= nil) then
|
||||
setmetatable(o, { __object = true, __keys = k })
|
||||
else
|
||||
objectMeta[o] = k
|
||||
end
|
||||
objectMeta[o] = keys or {}
|
||||
return o
|
||||
end
|
||||
function Types.isObject(v: any): boolean
|
||||
return type(v) == "table" and objectMeta[v] ~= nil
|
||||
return type(v) == "table" and orderOf(v) ~= nil
|
||||
end
|
||||
function Types.set(o: { [any]: any }, k: any, v: any)
|
||||
local order = objectMeta[o]
|
||||
local order = orderOf(o)
|
||||
if order and o[k] == nil and v ~= nil then
|
||||
table.insert(order, k)
|
||||
if order == NOKEYS then
|
||||
local mt: any = getmetatable(o)
|
||||
if type(mt) == "table" and rawget(mt, "__keys") == NOKEYS then
|
||||
mt.__keys = { k }
|
||||
else
|
||||
objectMeta[o] = { k }
|
||||
end
|
||||
else
|
||||
table.insert(order, k)
|
||||
end
|
||||
end
|
||||
o[k] = v
|
||||
end
|
||||
@@ -702,25 +726,31 @@ function Types.isArray(t: { [any]: any }, emptyIsMap: boolean?): boolean
|
||||
return c == n
|
||||
end
|
||||
function Types.keys(t: { [any]: any }): { any }
|
||||
local order = objectMeta[t]
|
||||
local order = orderOf(t)
|
||||
local out, seen = {}, {}
|
||||
local n = 0
|
||||
if order then
|
||||
for _, k in order do
|
||||
if t[k] ~= nil and not seen[k] then
|
||||
seen[k] = true
|
||||
table.insert(out, k)
|
||||
n += 1
|
||||
out[n] = k
|
||||
end
|
||||
end
|
||||
end
|
||||
local rest = {}
|
||||
local rest: { any }? = nil
|
||||
for k in next, t do
|
||||
if not seen[k] then
|
||||
table.insert(rest, k)
|
||||
if rest then
|
||||
table.insert(rest, k)
|
||||
else
|
||||
rest = { k }
|
||||
end
|
||||
end
|
||||
end
|
||||
if #rest > 0 then
|
||||
if rest then
|
||||
table.sort(rest, keyLess)
|
||||
table.move(rest, 1, #rest, #out + 1, out)
|
||||
table.move(rest, 1, #rest, n + 1, out)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
@@ -202,6 +202,13 @@ function Decode.decompress(src: buffer, off: number, len: number, maxBytes: numb
|
||||
local bb, bc = 0, 0
|
||||
|
||||
local function fill()
|
||||
if bc <= 24 and ip + 4 <= lim then
|
||||
bb = bor(bb, lshift(readu32(src, ip), bc))
|
||||
local nb = rshift(32 - bc, 3)
|
||||
ip += nb
|
||||
bc += nb * 8
|
||||
return
|
||||
end
|
||||
while bc <= 24 do
|
||||
local byte = 0
|
||||
if ip < lim then
|
||||
|
||||
@@ -11,9 +11,6 @@ local bcreate, bcopy, bfill, blen = buffer.create, buffer.copy, buffer.fill, buf
|
||||
|
||||
local Decode = {}
|
||||
|
||||
-- CRC-32/BZIP2 table (polynomial 0x04C11DB7, not reflected: core/Crc32)
|
||||
local CT = Crc32.MSB_TABLE
|
||||
Decode.crcTable = CT
|
||||
|
||||
local MASK = table.create(33, 0)
|
||||
for i = 0, 32 do
|
||||
@@ -413,8 +410,12 @@ function Decode.decode(b: buffer, o: number, e: number, maxBytes: number): (buff
|
||||
return nil, "block larger than its declared size", "corrupt"
|
||||
end
|
||||
local v = MTF[idx + 1]
|
||||
for k = idx, 1, -1 do
|
||||
MTF[k + 1] = MTF[k]
|
||||
if idx > 8 then
|
||||
table.move(MTF, 1, idx, 2)
|
||||
else
|
||||
for k = idx, 1, -1 do
|
||||
MTF[k + 1] = MTF[k]
|
||||
end
|
||||
end
|
||||
MTF[1] = v
|
||||
local ch = SEQ[v + 1]
|
||||
@@ -447,7 +448,7 @@ function Decode.decode(b: buffer, o: number, e: number, maxBytes: number): (buff
|
||||
out = grow(out, op, op + nblock + 4096)
|
||||
end
|
||||
local cap = blen(out)
|
||||
local crc = 0xFFFFFFFF
|
||||
local blockStart = op
|
||||
local tPos = rshift(readu32(T, origPtr * 4), 8)
|
||||
local last, run = -1, 0
|
||||
local i = 0
|
||||
@@ -468,9 +469,6 @@ function Decode.decode(b: buffer, o: number, e: number, maxBytes: number): (buff
|
||||
end
|
||||
bfill(out, op, last, ch)
|
||||
op += ch
|
||||
for _ = 1, ch do
|
||||
crc = bxor(lshift(crc, 8), CT[bxor(rshift(crc, 24), last) + 1])
|
||||
end
|
||||
end
|
||||
run = 0
|
||||
last = -1
|
||||
@@ -490,13 +488,12 @@ function Decode.decode(b: buffer, o: number, e: number, maxBytes: number): (buff
|
||||
end
|
||||
writeu8(out, op, ch)
|
||||
op += 1
|
||||
crc = bxor(lshift(crc, 8), CT[bxor(rshift(crc, 24), ch) + 1])
|
||||
end
|
||||
end
|
||||
if op > maxBytes then
|
||||
return nil, "output larger than maxBytes", "limit"
|
||||
end
|
||||
crc = bxor(crc, 0xFFFFFFFF)
|
||||
local crc = bxor(Crc32.msb(out, blockStart, op - blockStart, 0xFFFFFFFF), 0xFFFFFFFF)
|
||||
if crc ~= storedCrc then
|
||||
return nil, string.format("block CRC mismatch (%08x, expected %08x)", crc, storedCrc), "checksum"
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
-- Written from the format description (no third-party code); randomised blocks (bzip2 0.9.0 and older) are unsupported.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Decode = require("@rosetta/codecs/compress/Bzip2/Decode")
|
||||
|
||||
local Bzip2 = {}
|
||||
@@ -33,14 +34,9 @@ function Bzip2.decompress(buf: buffer | string, offset: number?, length: number?
|
||||
end
|
||||
|
||||
function Bzip2.crc(buf: buffer, offset: number?, length: number?): number
|
||||
local CT = Decode.crcTable
|
||||
local o = offset or 0
|
||||
local e = o + (length or (buffer.len(buf) - o))
|
||||
local c = 0xFFFFFFFF
|
||||
for i = o, e - 1 do
|
||||
c = bit32.bxor(bit32.lshift(c, 8), CT[bit32.bxor(bit32.rshift(c, 24), buffer.readu8(buf, i)) + 1])
|
||||
end
|
||||
return bit32.bxor(c, 0xFFFFFFFF)
|
||||
local n = length or (buffer.len(buf) - o)
|
||||
return bit32.bxor(Crc32.msb(buf, o, n, 0xFFFFFFFF), 0xFFFFFFFF)
|
||||
end
|
||||
|
||||
return Bzip2
|
||||
@@ -5,7 +5,7 @@
|
||||
-- block the cheapest of stored / fixed / dynamic Huffman, as zlib's levels.
|
||||
local Huffman = require("@rosetta/codecs/entropy/Huffman")
|
||||
|
||||
local readu8, writeu8, writeu16 = buffer.readu8, buffer.writeu8, buffer.writeu16
|
||||
local readu8, readu32, writeu8, writeu16 = buffer.readu8, buffer.readu32, buffer.writeu8, buffer.writeu16
|
||||
local bcreate, bcopy, blen = buffer.create, buffer.copy, buffer.len
|
||||
local floor = math.floor
|
||||
|
||||
@@ -136,27 +136,72 @@ local function storedBlock(o: Out, src: buffer, s: number, e: number, final: boo
|
||||
end
|
||||
|
||||
local function emitSymbols(o: Out, L: { number }, D: { number }, nsym: number, lcode: { number }, llen: { number }, dcodes: { number }, dlen: { number })
|
||||
ensure(o, nsym * 6 + 8) -- at most 15 + 5 + 15 + 13 bits a symbol
|
||||
local buf, op, acc, cnt = o.buf, o.op, o.acc, o.cnt
|
||||
-- acc holds cnt < 16 pending bits; each field is at most 15 bits, so acc stays below 2^31
|
||||
for i = 1, nsym do
|
||||
local l = L[i]
|
||||
if l < 256 then
|
||||
put(o, lcode[l + 1], llen[l + 1])
|
||||
acc += lcode[l + 1] * POW[cnt + 1]
|
||||
cnt += llen[l + 1]
|
||||
if cnt >= 16 then
|
||||
writeu16(buf, op, acc % 65536)
|
||||
acc //= 65536
|
||||
op += 2
|
||||
cnt -= 16
|
||||
end
|
||||
else
|
||||
local len = l - 256
|
||||
local c = LCODE[len]
|
||||
put(o, lcode[c + 1], llen[c + 1])
|
||||
acc += lcode[c + 1] * POW[cnt + 1]
|
||||
cnt += llen[c + 1]
|
||||
if cnt >= 16 then
|
||||
writeu16(buf, op, acc % 65536)
|
||||
acc //= 65536
|
||||
op += 2
|
||||
cnt -= 16
|
||||
end
|
||||
local xb = LEXTRA[len]
|
||||
if xb > 0 then
|
||||
put(o, len - LBASEOF[len], xb)
|
||||
acc += (len - LBASEOF[len]) * POW[cnt + 1]
|
||||
cnt += xb
|
||||
if cnt >= 16 then
|
||||
writeu16(buf, op, acc % 65536)
|
||||
acc //= 65536
|
||||
op += 2
|
||||
cnt -= 16
|
||||
end
|
||||
end
|
||||
local d = D[i]
|
||||
local dc = dcode(d)
|
||||
put(o, dcodes[dc + 1], dlen[dc + 1])
|
||||
local dc = if d <= 256 then DSMALL[d] else DLARGE[(d - 1) // 128 + 1]
|
||||
acc += dcodes[dc + 1] * POW[cnt + 1]
|
||||
cnt += dlen[dc + 1]
|
||||
if cnt >= 16 then
|
||||
writeu16(buf, op, acc % 65536)
|
||||
acc //= 65536
|
||||
op += 2
|
||||
cnt -= 16
|
||||
end
|
||||
xb = DEXT[dc + 1]
|
||||
if xb > 0 then
|
||||
put(o, d - DBASE[dc + 1], xb)
|
||||
acc += (d - DBASE[dc + 1]) * POW[cnt + 1]
|
||||
cnt += xb
|
||||
if cnt >= 16 then
|
||||
writeu16(buf, op, acc % 65536)
|
||||
acc //= 65536
|
||||
op += 2
|
||||
cnt -= 16
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
while cnt >= 8 do
|
||||
writeu8(buf, op, acc % 256)
|
||||
acc //= 256
|
||||
op += 1
|
||||
cnt -= 8
|
||||
end
|
||||
o.op, o.acc, o.cnt = op, acc, cnt
|
||||
put(o, lcode[257], llen[257]) -- end of block
|
||||
end
|
||||
|
||||
@@ -319,11 +364,6 @@ function Compress.raw(src: buffer, off: number, len: number, level: number): buf
|
||||
local function hash(p: number): number
|
||||
return ((readu8(src, p) * 251 + readu8(src, p + 1)) * 251 + readu8(src, p + 2)) % HSIZE
|
||||
end
|
||||
local function insert(p: number)
|
||||
local h = hash(p) + 1
|
||||
prev[p % WSIZE + 1] = head[h]
|
||||
head[h] = p
|
||||
end
|
||||
local function find(p: number, steps: number): (number, number)
|
||||
local maxLen = math.min(MAXMATCH, e - p)
|
||||
if maxLen < 3 then
|
||||
@@ -332,9 +372,20 @@ function Compress.raw(src: buffer, off: number, len: number, level: number): buf
|
||||
local best, bestDist = 2, 0
|
||||
local c = head[hash(p) + 1]
|
||||
local limit = p - WSIZE
|
||||
while c >= 0 and c > limit and steps > 0 do
|
||||
if readu8(src, c + best) == readu8(src, p + best) and readu8(src, c) == readu8(src, p) then
|
||||
local p0, pb = readu8(src, p), readu8(src, p + 2)
|
||||
local max4 = maxLen - 4
|
||||
if limit < -1 then
|
||||
limit = -1
|
||||
end
|
||||
for _ = 1, steps do
|
||||
if c <= limit then
|
||||
break
|
||||
end
|
||||
if readu8(src, c + best) == pb and readu8(src, c) == p0 then
|
||||
local k = 1
|
||||
while k <= max4 and readu32(src, c + k) == readu32(src, p + k) do
|
||||
k += 4
|
||||
end
|
||||
while k < maxLen and readu8(src, c + k) == readu8(src, p + k) do
|
||||
k += 1
|
||||
end
|
||||
@@ -343,6 +394,7 @@ function Compress.raw(src: buffer, off: number, len: number, level: number): buf
|
||||
if k >= nice or k >= maxLen then
|
||||
break
|
||||
end
|
||||
pb = readu8(src, p + k)
|
||||
end
|
||||
end
|
||||
local nc = prev[c % WSIZE + 1]
|
||||
@@ -350,7 +402,6 @@ function Compress.raw(src: buffer, off: number, len: number, level: number): buf
|
||||
break
|
||||
end
|
||||
c = nc
|
||||
steps -= 1
|
||||
end
|
||||
if best < 3 then
|
||||
return 0, 0
|
||||
@@ -369,7 +420,9 @@ function Compress.raw(src: buffer, off: number, len: number, level: number): buf
|
||||
local mlen, mdist = 0, 0
|
||||
if p <= stop3 then
|
||||
mlen, mdist = find(p, maxChain)
|
||||
insert(p)
|
||||
local h = ((readu8(src, p) * 251 + readu8(src, p + 1)) * 251 + readu8(src, p + 2)) % HSIZE + 1
|
||||
prev[p % WSIZE + 1] = head[h]
|
||||
head[h] = p
|
||||
if mlen >= 3 and mlen < lazyMax and p + 1 <= stop3 then
|
||||
local l2, d2 = find(p + 1, if mlen >= good then maxChain // 4 else maxChain)
|
||||
if l2 > mlen then
|
||||
@@ -377,7 +430,9 @@ function Compress.raw(src: buffer, off: number, len: number, level: number): buf
|
||||
L[nsym] = readu8(src, p)
|
||||
D[nsym] = 0
|
||||
p += 1
|
||||
insert(p)
|
||||
h = ((readu8(src, p) * 251 + readu8(src, p + 1)) * 251 + readu8(src, p + 2)) % HSIZE + 1
|
||||
prev[p % WSIZE + 1] = head[h]
|
||||
head[h] = p
|
||||
mlen, mdist = l2, d2
|
||||
end
|
||||
end
|
||||
@@ -388,9 +443,16 @@ function Compress.raw(src: buffer, off: number, len: number, level: number): buf
|
||||
D[nsym] = mdist
|
||||
local q = p + 1
|
||||
local qe = math.min(p + mlen, stop3 + 1)
|
||||
while q < qe do
|
||||
insert(q)
|
||||
q += 1
|
||||
if q < qe then
|
||||
local b1, b2 = readu8(src, q), readu8(src, q + 1)
|
||||
while q < qe do
|
||||
local b3 = readu8(src, q + 2)
|
||||
local h = ((b1 * 251 + b2) * 251 + b3) % HSIZE + 1
|
||||
prev[q % WSIZE + 1] = head[h]
|
||||
head[h] = q
|
||||
b1, b2 = b2, b3
|
||||
q += 1
|
||||
end
|
||||
end
|
||||
p += mlen
|
||||
else
|
||||
|
||||
@@ -23,6 +23,19 @@ local DEXT = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
|
||||
-- RFC 1951 3.2.7: the order the code-length code lengths are sent in
|
||||
local CLORDER = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }
|
||||
|
||||
-- table symbols: literals 0..255, end of block 256, invalid 257..511 (codes 286 / 287), lengths 512 + base * 8 + extra
|
||||
-- bits; distances base * 16 + extra bits
|
||||
local LMAP, DMAP = table.create(288, 300), table.create(30, 0)
|
||||
for i = 0, 256 do
|
||||
LMAP[i + 1] = i
|
||||
end
|
||||
for i = 1, 29 do
|
||||
LMAP[257 + i] = 512 + LBASE[i] * 8 + LEXT[i]
|
||||
end
|
||||
for i = 1, 30 do
|
||||
DMAP[i] = DBASE[i] * 16 + DEXT[i]
|
||||
end
|
||||
|
||||
local LITCAP = Huffman.capacity(288, LITBITS, 15)
|
||||
local DISTCAP = Huffman.capacity(32, DISTBITS, 15)
|
||||
local CLCAP = Huffman.capacity(19, CLBITS, 7)
|
||||
@@ -35,12 +48,15 @@ do
|
||||
bfill(l, 144, 9, 112)
|
||||
bfill(l, 256, 7, 24)
|
||||
bfill(l, 280, 8, 8)
|
||||
FLITS = Huffman.buildLsb(l, 0, 288, FLIT, LITBITS)
|
||||
FLITS = Huffman.buildLsbMap(l, 0, 288, FLIT, LITBITS, LMAP)
|
||||
local d = bcreate(30)
|
||||
bfill(d, 0, 5, 30)
|
||||
FDISTS = Huffman.buildLsb(d, 0, 30, FDIST, DISTBITS)
|
||||
FDISTS = Huffman.buildLsbMap(d, 0, 30, FDIST, DISTBITS, DMAP)
|
||||
end
|
||||
|
||||
-- scratch tables for dynamic blocks, shared by every call (raw never yields)
|
||||
local SLIT, SDIST, SCL, SLENS = bcreate(LITCAP * 4), bcreate(DISTCAP * 4), bcreate(CLCAP * 4), bcreate(320)
|
||||
|
||||
local Inflate = {}
|
||||
|
||||
local function grow(out: buffer, op: number, need: number): (buffer, number)
|
||||
@@ -62,9 +78,9 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
end
|
||||
local pos = start
|
||||
local bitbuf, bitcnt, over = 0, 0, 0
|
||||
local lt, dt = bcreate(LITCAP * 4), bcreate(DISTCAP * 4) :: buffer
|
||||
local clt = bcreate(CLCAP * 4)
|
||||
local lens = bcreate(320)
|
||||
local lt, dt = SLIT, SDIST
|
||||
local clt = SCL
|
||||
local lens = SLENS
|
||||
local final = 0
|
||||
repeat
|
||||
-- block header (3 bits); also up to 14 bits of a dynamic header
|
||||
@@ -133,9 +149,7 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
lt, dt = FLIT, FDIST
|
||||
lsub, dsub = FLITS, FDISTS
|
||||
elseif btype == 2 then
|
||||
if lt == FLIT then
|
||||
lt, dt = bcreate(LITCAP * 4), bcreate(DISTCAP * 4) :: buffer
|
||||
end
|
||||
lt, dt = SLIT, SDIST
|
||||
local hlit = band(bitbuf, 31) + 257
|
||||
local hdist = band(rshift(bitbuf, 5), 31) + 1
|
||||
local hclen = band(rshift(bitbuf, 10), 15) + 4
|
||||
@@ -240,8 +254,8 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
if readu8(lens, 256) == 0 then
|
||||
return nil, "missing end-of-block code"
|
||||
end
|
||||
lsub = Huffman.buildLsb(lens, 0, hlit, lt, LITBITS)
|
||||
dsub = Huffman.buildLsb(lens, hlit, hdist, dt, DISTBITS)
|
||||
lsub = Huffman.buildLsbMap(lens, 0, hlit, lt, LITBITS, LMAP)
|
||||
dsub = Huffman.buildLsbMap(lens, hlit, hdist, dt, DISTBITS, DMAP)
|
||||
if lsub < 0 or dsub < 0 then
|
||||
return nil, "invalid literal/length or distance code set"
|
||||
end
|
||||
@@ -299,13 +313,12 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
end
|
||||
writeu8(out, op, sym)
|
||||
op += 1
|
||||
elseif sym == 256 then
|
||||
break
|
||||
else
|
||||
sym -= 256
|
||||
if sym > 29 then
|
||||
return nil, "invalid literal/length code"
|
||||
elseif sym < 512 then
|
||||
if sym == 256 then
|
||||
break
|
||||
end
|
||||
return nil, "invalid literal/length code"
|
||||
else
|
||||
if bitcnt < 20 then
|
||||
if pos + 4 <= endpos then
|
||||
bitbuf = bor(bitbuf, lshift(readu32(src, pos), bitcnt))
|
||||
@@ -327,8 +340,8 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
end
|
||||
end
|
||||
end
|
||||
local len = LBASE[sym]
|
||||
local xb = LEXT[sym]
|
||||
local len = rshift(sym, 3) - 64
|
||||
local xb = band(sym, 7)
|
||||
if xb > 0 then
|
||||
len += band(bitbuf, lshift(1, xb) - 1)
|
||||
bitbuf = rshift(bitbuf, xb)
|
||||
@@ -348,12 +361,9 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
end
|
||||
bitbuf = rshift(bitbuf, l)
|
||||
bitcnt -= l
|
||||
local dsym = rshift(e, 5) + 1
|
||||
if dsym > 30 then
|
||||
return nil, "invalid distance code"
|
||||
end
|
||||
local dist = DBASE[dsym]
|
||||
xb = DEXT[dsym]
|
||||
local dsym = rshift(e, 5)
|
||||
local dist = rshift(dsym, 4)
|
||||
xb = band(dsym, 15)
|
||||
if xb > 0 then
|
||||
if bitcnt < 13 then
|
||||
if pos + 4 <= endpos then
|
||||
@@ -394,8 +404,11 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
end
|
||||
local s = op - dist
|
||||
if dist >= len then
|
||||
if len <= 16 and op + 16 <= cap then
|
||||
-- straight-line 16-byte copy for simple LuaJIT traces; it reads only bytes before op or already copied ones
|
||||
if len <= 8 and op + 8 <= cap then
|
||||
-- straight-line 8- / 16-byte copies for simple LuaJIT traces; they read only bytes before op or already copied ones
|
||||
writeu32(out, op, readu32(out, s))
|
||||
writeu32(out, op + 4, readu32(out, s + 4))
|
||||
elseif len <= 16 and op + 16 <= cap then
|
||||
writeu32(out, op, readu32(out, s))
|
||||
writeu32(out, op + 4, readu32(out, s + 4))
|
||||
writeu32(out, op + 8, readu32(out, s + 8))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
-- codecs/compress/Lzma/Crc64: CRC-64/XZ (ECMA-182 polynomial, reflected: 0xC96C5795D7870F42), xz check type 4.
|
||||
-- Written from the xz file format specification; the 64-bit value is kept as two u32 halves (hi, lo).
|
||||
local band, bxor, rshift, lshift, bor = bit32.band, bit32.bxor, bit32.rshift, bit32.lshift, bit32.bor
|
||||
local readu8 = buffer.readu8
|
||||
local readu8, readu32 = buffer.readu8, buffer.readu32
|
||||
|
||||
local THI, TLO = table.create(256, 0), table.create(256, 0)
|
||||
for n = 0, 255 do
|
||||
@@ -21,14 +21,43 @@ for n = 0, 255 do
|
||||
THI[n + 1], TLO[n + 1] = hi, lo
|
||||
end
|
||||
|
||||
-- slice-by-4: H[k] / L[k][n] = the register after byte n and k zero bytes
|
||||
local H1, H2, H3 = table.create(256, 0), table.create(256, 0), table.create(256, 0)
|
||||
local L1, L2, L3 = table.create(256, 0), table.create(256, 0), table.create(256, 0)
|
||||
for n = 0, 255 do
|
||||
local hi, lo = THI[n + 1], TLO[n + 1]
|
||||
for k = 1, 3 do
|
||||
local idx = band(lo, 255) + 1
|
||||
lo = bxor(TLO[idx], bor(rshift(lo, 8), lshift(band(hi, 255), 24)))
|
||||
hi = bxor(THI[idx], rshift(hi, 8))
|
||||
if k == 1 then
|
||||
H1[n + 1], L1[n + 1] = hi, lo
|
||||
elseif k == 2 then
|
||||
H2[n + 1], L2[n + 1] = hi, lo
|
||||
else
|
||||
H3[n + 1], L3[n + 1] = hi, lo
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local Crc64 = {}
|
||||
|
||||
function Crc64.of(b: buffer, o: number, n: number): (number, number)
|
||||
local hi, lo = 0xFFFFFFFF, 0xFFFFFFFF
|
||||
for i = o, o + n - 1 do
|
||||
local i, e = o, o + n
|
||||
local e4 = e - 4
|
||||
while i <= e4 do
|
||||
local w = bxor(lo, readu32(b, i))
|
||||
local a, c, d, f = band(w, 255) + 1, band(rshift(w, 8), 255) + 1, band(rshift(w, 16), 255) + 1, rshift(w, 24) + 1
|
||||
lo = bxor(L3[a], L2[c], L1[d], TLO[f], hi)
|
||||
hi = bxor(H3[a], H2[c], H1[d], THI[f])
|
||||
i += 4
|
||||
end
|
||||
while i < e do
|
||||
local idx = band(bxor(lo, readu8(b, i)), 255) + 1
|
||||
lo = bxor(TLO[idx], bor(rshift(lo, 8), lshift(band(hi, 255), 24)))
|
||||
hi = bxor(THI[idx], rshift(hi, 8))
|
||||
i += 1
|
||||
end
|
||||
return bxor(hi, 0xFFFFFFFF), bxor(lo, 0xFFFFFFFF)
|
||||
end
|
||||
|
||||
@@ -659,14 +659,24 @@ local function block(b: buffer, p: number, e: number, st: any): (string?, string
|
||||
local ml = ML_BASE[mlCode]
|
||||
local nb = ML_BITS[mlCode]
|
||||
if nb > 0 then
|
||||
ml += peek(b, s, off, nb)
|
||||
off -= nb
|
||||
local lo = off - nb
|
||||
if lo >= 0 and s + rshift(lo, 3) <= fastEnd then
|
||||
ml += band(rshift(readu32(b, s + rshift(lo, 3)), band(lo, 7)), lshift(1, nb) - 1)
|
||||
else
|
||||
ml += peek(b, s, off, nb)
|
||||
end
|
||||
off = lo
|
||||
end
|
||||
local ll = LL_BASE[llCode]
|
||||
nb = LL_BITS[llCode]
|
||||
if nb > 0 then
|
||||
ll += peek(b, s, off, nb)
|
||||
off -= nb
|
||||
local lo = off - nb
|
||||
if lo >= 0 and s + rshift(lo, 3) <= fastEnd then
|
||||
ll += band(rshift(readu32(b, s + rshift(lo, 3)), band(lo, 7)), lshift(1, nb) - 1)
|
||||
else
|
||||
ll += peek(b, s, off, nb)
|
||||
end
|
||||
off = lo
|
||||
end
|
||||
-- repeat offsets
|
||||
local offset
|
||||
@@ -699,15 +709,31 @@ local function block(b: buffer, p: number, e: number, st: any): (string?, string
|
||||
end
|
||||
-- state updates (not after the last sequence): LL, ML, OF
|
||||
if i < nbSeq then
|
||||
local lo
|
||||
nb = band(rshift(llE, 8), 255)
|
||||
llS = rshift(llE, 16) + peek(b, s, off, nb)
|
||||
off -= nb
|
||||
lo = off - nb
|
||||
if lo >= 0 and s + rshift(lo, 3) <= fastEnd then
|
||||
llS = rshift(llE, 16) + band(rshift(readu32(b, s + rshift(lo, 3)), band(lo, 7)), lshift(1, nb) - 1)
|
||||
else
|
||||
llS = rshift(llE, 16) + peek(b, s, off, nb)
|
||||
end
|
||||
off = lo
|
||||
nb = band(rshift(mlE, 8), 255)
|
||||
mlS = rshift(mlE, 16) + peek(b, s, off, nb)
|
||||
off -= nb
|
||||
lo = off - nb
|
||||
if lo >= 0 and s + rshift(lo, 3) <= fastEnd then
|
||||
mlS = rshift(mlE, 16) + band(rshift(readu32(b, s + rshift(lo, 3)), band(lo, 7)), lshift(1, nb) - 1)
|
||||
else
|
||||
mlS = rshift(mlE, 16) + peek(b, s, off, nb)
|
||||
end
|
||||
off = lo
|
||||
nb = band(rshift(ofE, 8), 255)
|
||||
ofS = rshift(ofE, 16) + peek(b, s, off, nb)
|
||||
off -= nb
|
||||
lo = off - nb
|
||||
if lo >= 0 and s + rshift(lo, 3) <= fastEnd then
|
||||
ofS = rshift(ofE, 16) + band(rshift(readu32(b, s + rshift(lo, 3)), band(lo, 7)), lshift(1, nb) - 1)
|
||||
else
|
||||
ofS = rshift(ofE, 16) + peek(b, s, off, nb)
|
||||
end
|
||||
off = lo
|
||||
end
|
||||
-- execute
|
||||
if lp + ll > litEnd then
|
||||
|
||||
@@ -38,7 +38,7 @@ end
|
||||
local count = table.create(MAXLEN + 1, 0)
|
||||
local nextc = table.create(MAXLEN + 1, 0)
|
||||
|
||||
local function build(lens: buffer, off: number, n: number, tab: buffer, P: number, msb: boolean): number
|
||||
local function build(lens: buffer, off: number, n: number, tab: buffer, P: number, msb: boolean, map: { number }?): number
|
||||
for i = 1, MAXLEN + 1 do
|
||||
count[i] = 0
|
||||
end
|
||||
@@ -76,7 +76,7 @@ local function build(lens: buffer, off: number, n: number, tab: buffer, P: numbe
|
||||
if l > 0 then
|
||||
local c = nextc[l]
|
||||
nextc[l] = c + 1
|
||||
local entry = s * 32 + l
|
||||
local entry = (if map then map[s + 1] else s) * 32 + l
|
||||
if l <= P then
|
||||
if msb then
|
||||
local first = lshift(c, P - l)
|
||||
@@ -136,6 +136,11 @@ function Huffman.buildLsb(lens: buffer, off: number, n: number, tab: buffer, P:
|
||||
return build(lens, off, n, tab, P, false)
|
||||
end
|
||||
|
||||
-- map[s + 1] replaces symbol s in the entries (values < 2^27)
|
||||
function Huffman.buildLsbMap(lens: buffer, off: number, n: number, tab: buffer, P: number, map: { number }): number
|
||||
return build(lens, off, n, tab, P, false, map)
|
||||
end
|
||||
|
||||
function Huffman.buildMsb(lens: buffer, off: number, n: number, tab: buffer, P: number): number
|
||||
return build(lens, off, n, tab, P, true)
|
||||
end
|
||||
|
||||
@@ -29,6 +29,8 @@ local ESC: { [number]: string } = {
|
||||
[116] = "\t",
|
||||
}
|
||||
|
||||
local WS: { [number]: boolean } = { [32] = true, [9] = true, [10] = true, [13] = true }
|
||||
|
||||
local utf8char = Text.utf8char
|
||||
Decode.utf8char = utf8char
|
||||
|
||||
@@ -164,7 +166,9 @@ function Decode.value(s: string, i: number, opts: Options?): (any, any, number?)
|
||||
local value: any
|
||||
|
||||
while true do
|
||||
i = match(s, "^[ \t\n\r]*()", i) :: any
|
||||
if WS[byte(s, i) or 0] then
|
||||
i = match(s, "^[ \t\n\r]*()", i) :: any
|
||||
end
|
||||
local c = byte(s, i)
|
||||
local haveValue = true
|
||||
if c == 123 then -- {
|
||||
@@ -172,7 +176,10 @@ function Decode.value(s: string, i: number, opts: Options?): (any, any, number?)
|
||||
if depth > maxDepth then
|
||||
return nil, "nested deeper than " .. maxDepth, i - 1
|
||||
end
|
||||
i = match(s, "^[ \t\n\r]*()", i + 1) :: any
|
||||
i = i + 1
|
||||
if WS[byte(s, i) or 0] then
|
||||
i = match(s, "^[ \t\n\r]*()", i) :: any
|
||||
end
|
||||
local t = {}
|
||||
c = byte(s, i)
|
||||
if c == 125 then
|
||||
@@ -184,7 +191,10 @@ function Decode.value(s: string, i: number, opts: Options?): (any, any, number?)
|
||||
if k == nil then
|
||||
return nil, ni, at
|
||||
end
|
||||
i = match(s, "^[ \t\n\r]*()", ni) :: any
|
||||
i = ni
|
||||
if WS[byte(s, i) or 0] then
|
||||
i = match(s, "^[ \t\n\r]*()", i) :: any
|
||||
end
|
||||
if byte(s, i) ~= 58 then
|
||||
return nil, if i > n then "truncated object" else "expected ':'", i - 1
|
||||
end
|
||||
@@ -200,7 +210,10 @@ function Decode.value(s: string, i: number, opts: Options?): (any, any, number?)
|
||||
if depth > maxDepth then
|
||||
return nil, "nested deeper than " .. maxDepth, i - 1
|
||||
end
|
||||
i = match(s, "^[ \t\n\r]*()", i + 1) :: any
|
||||
i = i + 1
|
||||
if WS[byte(s, i) or 0] then
|
||||
i = match(s, "^[ \t\n\r]*()", i) :: any
|
||||
end
|
||||
if byte(s, i) == 93 then
|
||||
i += 1
|
||||
depth -= 1
|
||||
@@ -256,10 +269,15 @@ function Decode.value(s: string, i: number, opts: Options?): (any, any, number?)
|
||||
t[cnt] = value
|
||||
stackK[depth] = cnt
|
||||
end
|
||||
i = match(s, "^[ \t\n\r]*()", i) :: any
|
||||
if WS[byte(s, i) or 0] then
|
||||
i = match(s, "^[ \t\n\r]*()", i) :: any
|
||||
end
|
||||
c = byte(s, i)
|
||||
if c == 44 then -- ,
|
||||
i = match(s, "^[ \t\n\r]*()", i + 1) :: any
|
||||
i = i + 1
|
||||
if WS[byte(s, i) or 0] then
|
||||
i = match(s, "^[ \t\n\r]*()", i) :: any
|
||||
end
|
||||
if ord then
|
||||
if byte(s, i) ~= 34 then
|
||||
return nil, if i > n then "truncated object" else "expected a key", i - 1
|
||||
@@ -268,7 +286,10 @@ function Decode.value(s: string, i: number, opts: Options?): (any, any, number?)
|
||||
if k == nil then
|
||||
return nil, ni, at
|
||||
end
|
||||
i = match(s, "^[ \t\n\r]*()", ni) :: any
|
||||
i = ni
|
||||
if WS[byte(s, i) or 0] then
|
||||
i = match(s, "^[ \t\n\r]*()", i) :: any
|
||||
end
|
||||
if byte(s, i) ~= 58 then
|
||||
return nil, if i > n then "truncated object" else "expected ':'", i - 1
|
||||
end
|
||||
|
||||
@@ -140,18 +140,23 @@ type State = {
|
||||
maxDepth: number,
|
||||
null: any,
|
||||
err: string?,
|
||||
nls: { string }, -- "\n" .. indent * (i - 1)
|
||||
}
|
||||
|
||||
local function put(st: State, s: string)
|
||||
local n = st.n + 1
|
||||
st.out[n] = s
|
||||
st.n = n
|
||||
local function newline(st: State, depth: number): string
|
||||
local r = "\n" .. string.rep(st.indent :: string, depth)
|
||||
st.nls[depth + 1] = r
|
||||
return r
|
||||
end
|
||||
|
||||
local function value(st: State, v: any, depth: number): boolean
|
||||
local tv = type(v)
|
||||
local out = st.out
|
||||
local n: number
|
||||
if tv == "string" then
|
||||
put(st, quote(v, st.ascii, st.slash))
|
||||
n = st.n + 1
|
||||
out[n] = quote(v, st.ascii, st.slash)
|
||||
st.n = n
|
||||
elseif tv == "number" then
|
||||
local s = number(v)
|
||||
if not s then
|
||||
@@ -161,14 +166,22 @@ local function value(st: State, v: any, depth: number): boolean
|
||||
end
|
||||
s = "null"
|
||||
end
|
||||
put(st, s)
|
||||
n = st.n + 1
|
||||
out[n] = s
|
||||
st.n = n
|
||||
elseif tv == "boolean" then
|
||||
put(st, if v then "true" else "false")
|
||||
n = st.n + 1
|
||||
out[n] = if v then "true" else "false"
|
||||
st.n = n
|
||||
elseif v == nil or v == st.null or v == Types.null then
|
||||
put(st, "null")
|
||||
n = st.n + 1
|
||||
out[n] = "null"
|
||||
st.n = n
|
||||
elseif tv == "table" then
|
||||
if Types.Date.is(v) then
|
||||
put(st, '"' .. tostring(v) .. '"')
|
||||
n = st.n + 1
|
||||
out[n] = '"' .. tostring(v) .. '"'
|
||||
st.n = n
|
||||
return true
|
||||
end
|
||||
if depth >= st.maxDepth then
|
||||
@@ -178,31 +191,44 @@ local function value(st: State, v: any, depth: number): boolean
|
||||
local ind = st.indent
|
||||
local nl, nl2 = "", ""
|
||||
if ind then
|
||||
nl = "\n" .. string.rep(ind, depth + 1)
|
||||
nl2 = "\n" .. string.rep(ind, depth)
|
||||
local nls = st.nls
|
||||
nl = nls[depth + 2] or newline(st, depth + 1)
|
||||
nl2 = nls[depth + 1] or newline(st, depth)
|
||||
end
|
||||
if kind(v, st.emptyObject) == "array" then
|
||||
local n = #v
|
||||
if n == 0 then
|
||||
put(st, "[]")
|
||||
local len = #v
|
||||
if len == 0 then
|
||||
n = st.n + 1
|
||||
out[n] = "[]"
|
||||
st.n = n
|
||||
return true
|
||||
end
|
||||
put(st, "[")
|
||||
for i = 1, n do
|
||||
n = st.n + 1
|
||||
out[n] = "["
|
||||
st.n = n
|
||||
for i = 1, len do
|
||||
if i > 1 then
|
||||
put(st, ",")
|
||||
n = st.n + 1
|
||||
out[n] = ","
|
||||
st.n = n
|
||||
end
|
||||
if ind then
|
||||
put(st, nl)
|
||||
n = st.n + 1
|
||||
out[n] = nl
|
||||
st.n = n
|
||||
end
|
||||
if not value(st, v[i], depth + 1) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
if ind then
|
||||
put(st, nl2)
|
||||
n = st.n + 1
|
||||
out[n] = nl2
|
||||
st.n = n
|
||||
end
|
||||
put(st, "]")
|
||||
n = st.n + 1
|
||||
out[n] = "]"
|
||||
st.n = n
|
||||
else
|
||||
local keys: { any }
|
||||
if Types.isObject(v) then
|
||||
@@ -222,17 +248,25 @@ local function value(st: State, v: any, depth: number): boolean
|
||||
end
|
||||
end
|
||||
if #keys == 0 then
|
||||
put(st, "{}")
|
||||
n = st.n + 1
|
||||
out[n] = "{}"
|
||||
st.n = n
|
||||
return true
|
||||
end
|
||||
put(st, "{")
|
||||
n = st.n + 1
|
||||
out[n] = "{"
|
||||
st.n = n
|
||||
local sep = if ind then ": " else ":"
|
||||
for i, k in keys do
|
||||
if i > 1 then
|
||||
put(st, ",")
|
||||
n = st.n + 1
|
||||
out[n] = ","
|
||||
st.n = n
|
||||
end
|
||||
if ind then
|
||||
put(st, nl)
|
||||
n = st.n + 1
|
||||
out[n] = nl
|
||||
st.n = n
|
||||
end
|
||||
local ks: string
|
||||
if type(k) == "string" then
|
||||
@@ -243,16 +277,24 @@ local function value(st: State, v: any, depth: number): boolean
|
||||
st.err = "object key of type " .. type(k)
|
||||
return false
|
||||
end
|
||||
put(st, quote(ks, st.ascii, st.slash))
|
||||
put(st, sep)
|
||||
n = st.n + 1
|
||||
out[n] = quote(ks, st.ascii, st.slash)
|
||||
st.n = n
|
||||
n = st.n + 1
|
||||
out[n] = sep
|
||||
st.n = n
|
||||
if not value(st, v[k], depth + 1) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
if ind then
|
||||
put(st, nl2)
|
||||
n = st.n + 1
|
||||
out[n] = nl2
|
||||
st.n = n
|
||||
end
|
||||
put(st, "}")
|
||||
n = st.n + 1
|
||||
out[n] = "}"
|
||||
st.n = n
|
||||
end
|
||||
elseif tv == "buffer" then
|
||||
st.err = "cannot encode a buffer (encode it as base64 or an array first)"
|
||||
@@ -284,6 +326,7 @@ local function state(opts: Options?, nullv: any?): State
|
||||
maxDepth = o.maxDepth or 1000,
|
||||
null = nullv,
|
||||
err = nil,
|
||||
nls = {},
|
||||
}
|
||||
end
|
||||
Encode.state = state
|
||||
|
||||
@@ -18,6 +18,8 @@ export type Options = {
|
||||
}
|
||||
|
||||
local NAME = "^[%a_:\128-\255][%w_:%.%-\128-\255]*"
|
||||
local TEXT = "^([^<&%]%z\1-\8\11\12\14-\31]*)()<"
|
||||
local ATTR = '^[ \t\n]+([%a_:\128-\255][%w_:%.%-\128-\255]*)[ \t\n]*=[ \t\n]*"([^"<&%c]*)"()'
|
||||
local PREDEF: { [string]: string } = { lt = "<", gt = ">", amp = "&", quot = '"', apos = "'" }
|
||||
|
||||
local utf8char = Text.utf8char
|
||||
@@ -85,7 +87,7 @@ function Parse.toUtf8(s: string): (string?, string)
|
||||
if enc then
|
||||
local e = lower(enc)
|
||||
if e == "utf-8" or e == "utf8" or e == "us-ascii" or e == "ascii" then
|
||||
if find(s, "[\128-\255]") and not utf8.len(s) then
|
||||
if not utf8.len(s) then
|
||||
return nil, "invalid UTF-8"
|
||||
end
|
||||
return s, e
|
||||
@@ -100,7 +102,7 @@ function Parse.toUtf8(s: string): (string?, string)
|
||||
end
|
||||
return nil, "unsupported encoding " .. enc
|
||||
end
|
||||
if find(s, "[\128-\255]") and not utf8.len(s) then
|
||||
if not utf8.len(s) then
|
||||
return nil, "invalid UTF-8"
|
||||
end
|
||||
return s, "utf-8"
|
||||
@@ -494,11 +496,33 @@ function Parse.events(s: string, opts: Options?): () -> (string?, any, any, any)
|
||||
return nil
|
||||
end
|
||||
local c = byte(s, i)
|
||||
if c ~= 60 and depth > 0 and not keepWs and not preserve[depth] then
|
||||
local w = match(s, "^[ \t\n]*()", i) :: number
|
||||
local cw = byte(s, w)
|
||||
if cw == 60 then
|
||||
i = w
|
||||
c = 60
|
||||
elseif cw then
|
||||
-- text with a non-blank at w and no ']', '&' or control characters before the next '<'
|
||||
local raw, e = match(s, TEXT, i)
|
||||
if raw then
|
||||
i = e
|
||||
return "text", raw
|
||||
end
|
||||
end
|
||||
end
|
||||
if c ~= 60 then -- text
|
||||
local e = find(s, "<", i, true) or (n + 1)
|
||||
local raw = sub(s, i, e - 1)
|
||||
local start = i
|
||||
i = e
|
||||
if depth > 0 and not find(raw, "[%]&%z\1-\8\11\12\14-\31]") then
|
||||
-- no ']]>', control characters or references
|
||||
if keepWs or preserve[depth] or find(raw, "[^ \t\n]") then
|
||||
return "text", raw
|
||||
end
|
||||
continue
|
||||
end
|
||||
local wsOnly = not find(raw, "[^ \t\n]")
|
||||
if depth == 0 then
|
||||
if not wsOnly then
|
||||
@@ -524,6 +548,21 @@ function Parse.events(s: string, opts: Options?): () -> (string?, any, any, any)
|
||||
end
|
||||
local c2 = byte(s, i + 1)
|
||||
if c2 == 47 then -- </
|
||||
local top = stack[depth]
|
||||
if top then
|
||||
local tl = #top
|
||||
if byte(s, i + 2 + tl) == 62 and sub(s, i + 2, i + 1 + tl) == top then
|
||||
i += 3 + tl
|
||||
stack[depth] = nil
|
||||
nsStack[depth] = nil
|
||||
preserve[depth] = nil
|
||||
depth -= 1
|
||||
if depth == 0 then
|
||||
rootDone = true
|
||||
end
|
||||
return "end", top
|
||||
end
|
||||
end
|
||||
local name = match(s, NAME, i + 2)
|
||||
if not name then
|
||||
return fail("bad end tag", i)
|
||||
@@ -617,11 +656,35 @@ function Parse.events(s: string, opts: Options?): () -> (string?, any, any, any)
|
||||
end
|
||||
local at = i
|
||||
local p = i + 1 + #name
|
||||
local attrs = Types.object()
|
||||
local attrs = {}
|
||||
local order = {}
|
||||
local na = 0
|
||||
local closed = false
|
||||
local nsMap: { [string]: string }? = nil
|
||||
while true do
|
||||
if byte(s, p) == 62 then
|
||||
p += 1
|
||||
break
|
||||
end
|
||||
-- the common attribute: name="value" with no references, controls or '<' in the value
|
||||
local an, av, ae = match(s, ATTR, p)
|
||||
if an then
|
||||
if attrs[an] ~= nil then
|
||||
return fail("duplicate attribute " .. an, match(s, "^[ \t\n]*()", p) :: number)
|
||||
end
|
||||
attrs[an] = av
|
||||
na += 1
|
||||
order[na] = an
|
||||
if nsOn then
|
||||
if an == "xmlns" or sub(an, 1, 6) == "xmlns:" then
|
||||
local m: { [string]: string } = nsMap or {}
|
||||
nsMap = m
|
||||
m[if an == "xmlns" then "" else sub(an, 7)] = av
|
||||
end
|
||||
end
|
||||
p = ae
|
||||
continue
|
||||
end
|
||||
local q = match(s, "^[ \t\n]*()", p) :: any
|
||||
local cc = byte(s, q)
|
||||
if cc == 62 then
|
||||
@@ -675,7 +738,8 @@ function Parse.events(s: string, opts: Options?): () -> (string?, any, any, any)
|
||||
return fail("duplicate attribute " .. an, q)
|
||||
end
|
||||
attrs[an] = v
|
||||
table.insert(order, an)
|
||||
na += 1
|
||||
order[na] = an
|
||||
if nsOn then
|
||||
if an == "xmlns" or sub(an, 1, 6) == "xmlns:" then
|
||||
local m: { [string]: string } = nsMap or {}
|
||||
|
||||
@@ -78,7 +78,16 @@ function Xml.decode(src: string | buffer, opts: DecodeOptions?): (Node?, Err.Err
|
||||
local cur: any = doc
|
||||
local stack = { doc }
|
||||
local depth = 1
|
||||
for ev, a, b, c in Xml.events(src, o) do
|
||||
local s, terr = text(src)
|
||||
local u, enc = nil, ""
|
||||
if s then
|
||||
u, enc = Parse.toUtf8(s)
|
||||
end
|
||||
if not u then
|
||||
return nil, terr or Err.new(if find(enc, "unsupported", 1, true) then Err.UNSUPPORTED else Err.CORRUPT, enc)
|
||||
end
|
||||
local str: string = u
|
||||
for ev, a, b, c in Parse.events(str, o) do
|
||||
if ev == "start" then
|
||||
local node: any = { name = a, attrs = b, children = {}, parent = if parents then cur else nil }
|
||||
if c then
|
||||
@@ -118,7 +127,7 @@ function Xml.decode(src: string | buffer, opts: DecodeOptions?): (Node?, Err.Err
|
||||
elseif ev == "doctype" then
|
||||
doc.doctype = { raw = a, name = b.name, publicId = b.publicId, systemId = b.systemId, entities = b.entities }
|
||||
elseif ev == "error" then
|
||||
return nil, a
|
||||
return nil, Err.new(errCode(a, b, #str), a, b)
|
||||
end
|
||||
end
|
||||
return doc, nil
|
||||
@@ -126,7 +135,7 @@ end
|
||||
|
||||
function Xml.element(name: string, attrs: { [string]: string }?, children: { any }?): Node
|
||||
local a = attrs or Types.object()
|
||||
if not Types.isObject(a) then
|
||||
if attrs and not Types.isObject(a) then
|
||||
local keys = {}
|
||||
for k in next, a do
|
||||
table.insert(keys, k)
|
||||
@@ -161,24 +170,27 @@ function Xml.setAttr(node: Node, name: string, value: string?)
|
||||
Types.set(node.attrs, name, value)
|
||||
end
|
||||
|
||||
-- name == nil: any element; a name without a prefix also matches prefixed names with that local part
|
||||
local function matches(cn: string, name: string?, plain: boolean): boolean
|
||||
return name == nil or cn == name or (plain and find(cn, ":", 1, true) ~= nil and match(cn, ":(.*)$") == name)
|
||||
end
|
||||
|
||||
function Xml.children(node: Node, name: string?): { Node }
|
||||
local out = {}
|
||||
local plain = name ~= nil and not find(name, ":", 1, true)
|
||||
for _, ch in node.children do
|
||||
if type(ch) == "table" and string.byte(ch.name) ~= 35 then
|
||||
if name == nil or ch.name == name or (not find(name, ":", 1, true) and match(ch.name, ":(.*)$") == name) then
|
||||
table.insert(out, ch)
|
||||
end
|
||||
if type(ch) == "table" and string.byte(ch.name) ~= 35 and matches(ch.name, name, plain) then
|
||||
table.insert(out, ch)
|
||||
end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
function Xml.child(node: Node, name: string?): Node?
|
||||
local plain = name ~= nil and not find(name, ":", 1, true)
|
||||
for _, ch in node.children do
|
||||
if type(ch) == "table" and string.byte(ch.name) ~= 35 then
|
||||
if name == nil or ch.name == name or (not find(name, ":", 1, true) and match(ch.name, ":(.*)$") == name) then
|
||||
return ch
|
||||
end
|
||||
if type(ch) == "table" and string.byte(ch.name) ~= 35 and matches(ch.name, name, plain) then
|
||||
return ch
|
||||
end
|
||||
end
|
||||
return nil
|
||||
@@ -186,10 +198,11 @@ end
|
||||
|
||||
function Xml.descendants(node: Node, name: string?): { Node }
|
||||
local out = {}
|
||||
local plain = name ~= nil and not find(name, ":", 1, true)
|
||||
local function walk(n: Node)
|
||||
for _, ch in n.children do
|
||||
if type(ch) == "table" and string.byte(ch.name) ~= 35 then
|
||||
if name == nil or ch.name == name or (not find(name :: string, ":", 1, true) and match(ch.name, ":(.*)$") == name) then
|
||||
if matches(ch.name, name, plain) then
|
||||
table.insert(out, ch)
|
||||
end
|
||||
walk(ch)
|
||||
@@ -207,6 +220,13 @@ function Xml.text(node: any): string
|
||||
if node.name == "#cdata" then
|
||||
return node.text or ""
|
||||
end
|
||||
local kids = node.children
|
||||
local nk = #kids
|
||||
if nk == 0 then
|
||||
return ""
|
||||
elseif nk == 1 and type(kids[1]) == "string" then
|
||||
return kids[1]
|
||||
end
|
||||
local parts = {}
|
||||
local function walk(n: any)
|
||||
for _, ch in n.children do
|
||||
@@ -251,14 +271,32 @@ local TEXT_ESC = { ["&"] = "&", ["<"] = "<", [">"] = ">", ["\r"] = "&#
|
||||
local ATTR_ESC = { ["&"] = "&", ["<"] = "<", [">"] = ">", ['"'] = """, ["\t"] = "	", ["\n"] = " ", ["\r"] = " " }
|
||||
|
||||
function Xml.escape(s: string): string
|
||||
if not find(s, "[&<>\r]") then
|
||||
return s
|
||||
end
|
||||
return (gsub(s, "[&<>\r]", TEXT_ESC))
|
||||
end
|
||||
function Xml.escapeAttr(s: string): string
|
||||
if not find(s, '[&<>"\t\n\r]') then
|
||||
return s
|
||||
end
|
||||
return (gsub(s, '[&<>"\t\n\r]', ATTR_ESC))
|
||||
end
|
||||
|
||||
local goodNames: { [string]: boolean } = {}
|
||||
local nGood = 0
|
||||
local function badName(name: any): boolean
|
||||
return type(name) ~= "string" or not match(name, "^[%a_:\128-\255][%w_:%.%-\128-\255]*$")
|
||||
if goodNames[name] then
|
||||
return false
|
||||
end
|
||||
if type(name) ~= "string" or not match(name, "^[%a_:\128-\255][%w_:%.%-\128-\255]*$") then
|
||||
return true
|
||||
end
|
||||
if nGood < 4096 then
|
||||
goodNames[name] = true
|
||||
nGood += 1
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function Xml.encode(node: Node, opts: EncodeOptions?): (string?, Err.Err?)
|
||||
@@ -270,6 +308,15 @@ function Xml.encode(node: Node, opts: EncodeOptions?): (string?, Err.Err?)
|
||||
ind = o.indent
|
||||
end
|
||||
local selfClose = o.selfClose ~= false
|
||||
local indents: { string } = {}
|
||||
local function indent(depth: number): string
|
||||
local r = indents[depth + 1]
|
||||
if not r then
|
||||
r = "\n" .. string.rep(ind :: string, depth)
|
||||
indents[depth + 1] = r
|
||||
end
|
||||
return r
|
||||
end
|
||||
local out: { string } = {}
|
||||
local err: string? = nil
|
||||
local seen: { [any]: boolean } = {}
|
||||
@@ -324,7 +371,7 @@ function Xml.encode(node: Node, opts: EncodeOptions?): (string?, Err.Err?)
|
||||
end
|
||||
table.insert(out, "<" .. name)
|
||||
local attrs = n.attrs or {}
|
||||
for _, k in Types.keys(attrs) do
|
||||
for _, k in (if next(attrs) == nil then attrs else Types.keys(attrs)) do
|
||||
local v = attrs[k]
|
||||
if badName(k) then
|
||||
err = "bad attribute name " .. tostring(k)
|
||||
@@ -355,12 +402,12 @@ function Xml.encode(node: Node, opts: EncodeOptions?): (string?, Err.Err?)
|
||||
end
|
||||
for _, c in ch do
|
||||
if pretty then
|
||||
table.insert(out, "\n" .. string.rep(ind :: string, depth + 1))
|
||||
table.insert(out, indent(depth + 1))
|
||||
end
|
||||
write(c, depth + 1)
|
||||
end
|
||||
if pretty then
|
||||
table.insert(out, "\n" .. string.rep(ind :: string, depth))
|
||||
table.insert(out, indent(depth))
|
||||
end
|
||||
table.insert(out, "</" .. name .. ">")
|
||||
end
|
||||
|
||||
@@ -8,11 +8,9 @@
|
||||
-- of a multiplexed file come first when every stream's first packet is written (with flush) before any other.
|
||||
-- Never throws: a bad argument returns false, Err.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Page = require("@rosetta/containers/Ogg/Page")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
|
||||
local CRC = Page.CRC_TABLE
|
||||
local readu8, writeu8, writeu32, writei32 = buffer.readu8, buffer.writeu8, buffer.writeu32, buffer.writei32
|
||||
local bxor, lshift, rshift = bit32.bxor, bit32.lshift, bit32.rshift
|
||||
local writeu8, writeu32, writei32 = buffer.writeu8, buffer.writeu32, buffer.writei32
|
||||
|
||||
local Mux = {}
|
||||
Mux.__index = Mux
|
||||
@@ -63,11 +61,7 @@ end
|
||||
|
||||
-- the CRC of a page (the crc field written as zero)
|
||||
local function crc(b: buffer, n: number): number
|
||||
local c = 0
|
||||
for i = 0, n - 1 do
|
||||
c = bxor(lshift(c, 8), CRC[bxor(rshift(c, 24), readu8(b, i)) + 1])
|
||||
end
|
||||
return c
|
||||
return Crc32.msb(b, 0, n, 0)
|
||||
end
|
||||
|
||||
function Stream._flush(self: any, eos: boolean)
|
||||
|
||||
@@ -32,10 +32,7 @@ local CRC = Crc32.MSB_TABLE
|
||||
Page.CRC_TABLE = CRC
|
||||
|
||||
local function crcRange(b: buffer, from: number, to: number, crc: number): number
|
||||
for i = from, to - 1 do
|
||||
crc = bxor(lshift(crc, 8), CRC[bxor(rshift(crc, 24), readu8(b, i)) + 1])
|
||||
end
|
||||
return crc
|
||||
return Crc32.msb(b, from, to - from, crc)
|
||||
end
|
||||
|
||||
-- the Ogg CRC-32 of arbitrary data (the crc field is not zeroed)
|
||||
|
||||
@@ -2,24 +2,38 @@
|
||||
--!native
|
||||
-- core/Adler32: Adler-32 (RFC 1950, the zlib checksum). Absorbed from deflate-luau src/Deflate/Checksum.luau (same author;
|
||||
-- no third-party code). Never throws: the range is clamped.
|
||||
local readu8 = buffer.readu8
|
||||
local readu8, readu32 = buffer.readu8, buffer.readu32
|
||||
local band, rshift = bit32.band, bit32.rshift
|
||||
|
||||
local function adler32(buf: buffer, off: number, len: number, adler: number?): number
|
||||
local a0 = adler or 1
|
||||
local a, b = a0 % 65536, a0 // 65536
|
||||
local i, e = off, off + len
|
||||
while i < e do
|
||||
-- zlib NMAX: the largest n with 255 n (n + 1) / 2 + (n + 1) (BASE - 1) < 2^32
|
||||
local stop = math.min(e, i + 5552)
|
||||
while i < stop do
|
||||
a += readu8(buf, i)
|
||||
b += a
|
||||
i += 1
|
||||
-- 88-byte blocks, two bytes per 16-bit lane of each u32: pl / ph sum bytes 0, 2 / 1, 3 of the words, ql / qh sum
|
||||
-- those prefix sums (each lane stays below 2^16 over 22 words). Byte t of word j (of m) weighs 4 (m - j) - t in b.
|
||||
local e88 = e - 88
|
||||
while i <= e88 do
|
||||
local pl, ph, ql, qh = 0, 0, 0, 0
|
||||
for j = i, i + 84, 4 do
|
||||
local w = readu32(buf, j)
|
||||
pl += band(w, 0x00FF00FF)
|
||||
ph += band(rshift(w, 8), 0x00FF00FF)
|
||||
ql += pl
|
||||
qh += ph
|
||||
end
|
||||
a %= 65521
|
||||
b %= 65521
|
||||
i += 88
|
||||
local s0, s2 = pl % 65536, pl // 65536
|
||||
local s1, s3 = ph % 65536, ph // 65536
|
||||
local q = ql % 65536 + ql // 65536 + qh % 65536 + qh // 65536
|
||||
b = (b + 88 * a + 4 * q - s1 - 2 * s2 - 3 * s3) % 65521
|
||||
a = (a + s0 + s1 + s2 + s3) % 65521
|
||||
end
|
||||
return b * 65536 + a
|
||||
while i < e do
|
||||
a += readu8(buf, i)
|
||||
b += a
|
||||
i += 1
|
||||
end
|
||||
return (b % 65521) * 65536 + a % 65521
|
||||
end
|
||||
|
||||
local function range(buf: buffer, offset: number?, length: number?): (number, number)
|
||||
|
||||
@@ -29,7 +29,19 @@ for _, c in { 9, 10, 11, 12, 13, 32 } do
|
||||
end
|
||||
buffer.writeu8(DEC, string.byte("="), 65)
|
||||
|
||||
local readu8, writeu8 = buffer.readu8, buffer.writeu8
|
||||
local readu8, writeu8, readu16, readu32, writeu16 = buffer.readu8, buffer.writeu8, buffer.readu16, buffer.readu32, buffer.writeu16
|
||||
local band, bor, rshift, byteswap = bit32.band, bit32.bor, bit32.rshift, bit32.byteswap
|
||||
local writeu32 = buffer.writeu32
|
||||
|
||||
-- two output characters per 12 input bits (u16, first character in the low byte)
|
||||
local function pairs12(alpha: string): buffer
|
||||
local t = buffer.create(8192)
|
||||
for i = 0, 4095 do
|
||||
buffer.writeu16(t, i * 2, string.byte(alpha, i // 64 + 1) + string.byte(alpha, i % 64 + 1) * 256)
|
||||
end
|
||||
return t
|
||||
end
|
||||
local ENC2, ENC2_URL = pairs12(ALPHA), pairs12(ALPHA_URL)
|
||||
|
||||
function Base64.encode(data: buffer | string, opts: EncodeOptions?, offset: number?, length: number?): string
|
||||
local buf: buffer = if type(data) == "string" then buffer.fromstring(data) else data
|
||||
@@ -47,6 +59,24 @@ function Base64.encode(data: buffer | string, opts: EncodeOptions?, offset: numb
|
||||
local out = buffer.create(textLen + breaks)
|
||||
local p = 0
|
||||
local col = 0
|
||||
if wrap == 0 then
|
||||
local enc2 = if opts and opts.url then ENC2_URL else ENC2
|
||||
local fast = if o + full * 3 + 1 <= total then full else full - 1 -- readu32 reads one byte past the group
|
||||
for i = 0, fast - 1 do
|
||||
local v = rshift(byteswap(readu32(buf, o + i * 3)), 8)
|
||||
writeu16(out, p, readu16(enc2, rshift(v, 12) * 2))
|
||||
writeu16(out, p + 2, readu16(enc2, band(v, 4095) * 2))
|
||||
p += 4
|
||||
end
|
||||
for i = math.max(fast, 0), full - 1 do
|
||||
local q = o + i * 3
|
||||
local v = readu8(buf, q) * 65536 + readu8(buf, q + 1) * 256 + readu8(buf, q + 2)
|
||||
writeu16(out, p, readu16(enc2, rshift(v, 12) * 2))
|
||||
writeu16(out, p + 2, readu16(enc2, band(v, 4095) * 2))
|
||||
p += 4
|
||||
end
|
||||
full = 0
|
||||
end
|
||||
for i = 0, full - 1 do
|
||||
if wrap > 0 then
|
||||
if col == wrap then
|
||||
@@ -69,7 +99,7 @@ function Base64.encode(data: buffer | string, opts: EncodeOptions?, offset: numb
|
||||
writeu8(out, p, 10)
|
||||
p += 1
|
||||
end
|
||||
local q = o + full * 3
|
||||
local q = o + (n - rest)
|
||||
local v = readu8(buf, q) * 65536 + (if rest == 2 then readu8(buf, q + 1) * 256 else 0)
|
||||
writeu8(out, p, readu8(enc, v // 262144))
|
||||
writeu8(out, p + 1, readu8(enc, (v // 4096) % 64))
|
||||
@@ -85,13 +115,51 @@ function Base64.encode(data: buffer | string, opts: EncodeOptions?, offset: numb
|
||||
return buffer.tostring(out)
|
||||
end
|
||||
|
||||
-- 12 bits per two input characters (u16 index, first character in the low byte); 0xFFFF unless both are alphabet
|
||||
local DEC2: buffer? = nil
|
||||
local function pairDecoder(): buffer
|
||||
local t = buffer.create(131072)
|
||||
buffer.fill(t, 0, 255)
|
||||
for a = 0, 255 do
|
||||
local da = buffer.readu8(DEC, a)
|
||||
if da < 64 then
|
||||
for b = 0, 255 do
|
||||
local db = buffer.readu8(DEC, b)
|
||||
if db < 64 then
|
||||
buffer.writeu16(t, (a + b * 256) * 2, da * 64 + db)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
DEC2 = t
|
||||
return t
|
||||
end
|
||||
|
||||
function Base64.decode(s: string | buffer): (buffer?, string?)
|
||||
local src: buffer = if type(s) == "string" then buffer.fromstring(s) else s
|
||||
local n = buffer.len(src)
|
||||
local out = buffer.create((n // 4 + 1) * 3)
|
||||
local acc, bits, p = 0, 0, 0
|
||||
local padded = false
|
||||
for i = 0, n - 1 do
|
||||
local i = 0
|
||||
while i < n do
|
||||
if bits == 0 and not padded then
|
||||
-- whole groups of four alphabet characters; out has room for the fourth byte each u32 write adds
|
||||
local dec2 = DEC2 or pairDecoder()
|
||||
while i + 4 <= n do
|
||||
local w = readu32(src, i)
|
||||
local x, y = readu16(dec2, band(w, 65535) * 2), readu16(dec2, rshift(w, 16) * 2)
|
||||
if bor(x, y) >= 4096 then
|
||||
break
|
||||
end
|
||||
writeu32(out, p, rshift(byteswap(x * 4096 + y), 8))
|
||||
p += 3
|
||||
i += 4
|
||||
end
|
||||
if i >= n then
|
||||
break
|
||||
end
|
||||
end
|
||||
local d = readu8(DEC, readu8(src, i))
|
||||
if d < 64 then
|
||||
if padded then
|
||||
@@ -112,6 +180,7 @@ function Base64.decode(s: string | buffer): (buffer?, string?)
|
||||
elseif d ~= 64 then
|
||||
return nil, string.format("bad base64 character 0x%02x at %d", readu8(src, i), i)
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
if bits >= 6 then
|
||||
return nil, "truncated base64 (a single character in the last group)"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
--!native
|
||||
-- core/Crc32: CRC-32 (IEEE 802.3, the zlib / gzip / zip / PNG polynomial 0xEDB88320, reflected), slice-by-8.
|
||||
-- Absorbed from deflate-luau src/Deflate/Checksum.luau (same author; no third-party code). Never throws.
|
||||
local band, bxor, rshift, lshift = bit32.band, bit32.bxor, bit32.rshift, bit32.lshift
|
||||
local band, bxor, rshift, lshift, byteswap = bit32.band, bit32.bxor, bit32.rshift, bit32.lshift, bit32.byteswap
|
||||
local readu8, readu32 = buffer.readu8, buffer.readu32
|
||||
|
||||
local T0, T1, T2, T3 = table.create(256, 0), table.create(256, 0), table.create(256, 0), table.create(256, 0)
|
||||
@@ -99,10 +99,49 @@ for n = 0, 255 do
|
||||
end
|
||||
Crc32.MSB_TABLE = MSB
|
||||
|
||||
-- slice-by-8 for the MSB-first CRC: M[k][n] = the CRC register after byte n and k zero bytes
|
||||
local M1, M2, M3 = table.create(256, 0), table.create(256, 0), table.create(256, 0)
|
||||
local M4, M5, M6, M7 = table.create(256, 0), table.create(256, 0), table.create(256, 0), table.create(256, 0)
|
||||
for n = 0, 255 do
|
||||
local c = MSB[n + 1]
|
||||
c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1])
|
||||
M1[n + 1] = c
|
||||
c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1])
|
||||
M2[n + 1] = c
|
||||
c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1])
|
||||
M3[n + 1] = c
|
||||
c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1])
|
||||
M4[n + 1] = c
|
||||
c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1])
|
||||
M5[n + 1] = c
|
||||
c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1])
|
||||
M6[n + 1] = c
|
||||
c = bxor(lshift(c, 8), MSB[rshift(c, 24) + 1])
|
||||
M7[n + 1] = c
|
||||
end
|
||||
|
||||
function Crc32.msb(buf: buffer, off: number, len: number, init: number?): number
|
||||
local c = init or 0
|
||||
for i = off, off + len - 1 do
|
||||
local i, e = off, off + len
|
||||
local e8 = e - 8
|
||||
while i <= e8 do
|
||||
c = bxor(c, byteswap(readu32(buf, i)))
|
||||
local d = byteswap(readu32(buf, i + 4))
|
||||
c = bxor(
|
||||
M7[rshift(c, 24) + 1],
|
||||
M6[band(rshift(c, 16), 255) + 1],
|
||||
M5[band(rshift(c, 8), 255) + 1],
|
||||
M4[band(c, 255) + 1],
|
||||
M3[rshift(d, 24) + 1],
|
||||
M2[band(rshift(d, 16), 255) + 1],
|
||||
M1[band(rshift(d, 8), 255) + 1],
|
||||
MSB[band(d, 255) + 1]
|
||||
)
|
||||
i += 8
|
||||
end
|
||||
while i < e do
|
||||
c = bxor(lshift(c, 8), MSB[bxor(rshift(c, 24), readu8(buf, i)) + 1])
|
||||
i += 1
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
+15
-16
@@ -51,22 +51,21 @@ local function compress(st: State, blk: buffer, o: number)
|
||||
M[i + 1] = readu32(blk, o + i * 4)
|
||||
end
|
||||
local a, b, c, d = st.a, st.b, st.c, st.d
|
||||
for i = 0, 63 do
|
||||
local f
|
||||
if i < 16 then
|
||||
f = bor(band(b, c), band(bnot(b), d))
|
||||
elseif i < 32 then
|
||||
f = bor(band(d, b), band(bnot(d), c))
|
||||
elseif i < 48 then
|
||||
f = bxor(b, c, d)
|
||||
else
|
||||
f = bxor(c, bor(b, bnot(d)))
|
||||
end
|
||||
local tmp = d
|
||||
d = c
|
||||
c = b
|
||||
b = (b + lrotate((a + f + K[i + 1] + M[G[i + 1] + 1]) % 4294967296, S[i + 1])) % 4294967296
|
||||
a = tmp
|
||||
for i = 1, 16 do
|
||||
local f = bor(band(b, c), band(bnot(b), d))
|
||||
a, b, c, d = d, (b + lrotate(a + f + K[i] + M[G[i] + 1], S[i])) % 4294967296, b, c
|
||||
end
|
||||
for i = 17, 32 do
|
||||
local f = bor(band(d, b), band(bnot(d), c))
|
||||
a, b, c, d = d, (b + lrotate(a + f + K[i] + M[G[i] + 1], S[i])) % 4294967296, b, c
|
||||
end
|
||||
for i = 33, 48 do
|
||||
local f = bxor(b, c, d)
|
||||
a, b, c, d = d, (b + lrotate(a + f + K[i] + M[G[i] + 1], S[i])) % 4294967296, b, c
|
||||
end
|
||||
for i = 49, 64 do
|
||||
local f = bxor(c, bor(b, bnot(d)))
|
||||
a, b, c, d = d, (b + lrotate(a + f + K[i] + M[G[i] + 1], S[i])) % 4294967296, b, c
|
||||
end
|
||||
st.a = (st.a + a) % 4294967296
|
||||
st.b = (st.b + b) % 4294967296
|
||||
|
||||
+40
-4
@@ -76,6 +76,8 @@ local function find(key: string, category: string?): Registry.Entry?
|
||||
return nil
|
||||
end
|
||||
|
||||
local LATE: { [string]: number } = { br = 0.3 } -- archive/br: a trial decode of up to 256 KB
|
||||
|
||||
local function detect(buf: buffer, name: string?, category: string?, format: string?): (Registry.Entry?, Err.Err?)
|
||||
if format then
|
||||
local e = find(format, category)
|
||||
@@ -86,18 +88,52 @@ local function detect(buf: buffer, name: string?, category: string?, format: str
|
||||
end
|
||||
local ext = Input.extension(name)
|
||||
local best: Registry.Entry? = nil
|
||||
local bestScore = 0
|
||||
for _, e in Registry do
|
||||
local bestScore, bestIdx = 0, 0
|
||||
-- sniffs score 0..1 (core/Sniff); the extension's format scoring 1 cannot be beaten. Formats with a costly sniff
|
||||
-- (LATE: the most they score) run last, and only when they could still win; ties go to registry order.
|
||||
local late: { number }? = nil
|
||||
for idx, e in Registry do
|
||||
if inCategory(e, category) and (e.caps.decode or e.caps.open) then
|
||||
local cap = LATE[e.name]
|
||||
if cap then
|
||||
late = late or {}
|
||||
table.insert(late :: { number }, idx)
|
||||
continue
|
||||
end
|
||||
local m = module(e)
|
||||
if m and m.sniff then
|
||||
local ok, score = pcall(m.sniff, Bytes.reader(buf))
|
||||
if ok and type(score) == "number" and score > 0 then
|
||||
if ext and table.find(e.extensions, ext) then
|
||||
local extHit = ext and table.find(e.extensions, ext)
|
||||
if extHit then
|
||||
score += 0.01 -- ties go to the extension
|
||||
end
|
||||
if score > bestScore then
|
||||
best, bestScore = e, score
|
||||
best, bestScore, bestIdx = e, score, idx
|
||||
if extHit and score >= 1.01 then
|
||||
return e, nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if late then
|
||||
for _, idx in late do
|
||||
local e = Registry[idx]
|
||||
local extHit = ext and table.find(e.extensions, ext)
|
||||
local cap = LATE[e.name] + (if extHit then 0.01 else 0)
|
||||
if cap > bestScore or (cap == bestScore and idx < bestIdx) then
|
||||
local m = module(e)
|
||||
if m and m.sniff then
|
||||
local ok, score = pcall(m.sniff, Bytes.reader(buf))
|
||||
if ok and type(score) == "number" and score > 0 then
|
||||
if extHit then
|
||||
score += 0.01
|
||||
end
|
||||
if score > bestScore or (score == bestScore and idx < bestIdx) then
|
||||
best, bestScore, bestIdx = e, score, idx
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -151,11 +151,12 @@ function Mtl.toMaterial(e: Entry, texture: (Map) -> number): Types.Material
|
||||
return m
|
||||
end
|
||||
|
||||
local NUM_FORMATS = { "%.6g", "%.9g", "%.17g" }
|
||||
local function num(v: number): string
|
||||
if v == math.floor(v) and math.abs(v) < 1e15 then
|
||||
return string.format("%d", v)
|
||||
end
|
||||
for _, f in { "%.6g", "%.9g", "%.17g" } do
|
||||
for _, f in NUM_FORMATS do
|
||||
local s = string.format(f, v)
|
||||
if tonumber(s) == v then
|
||||
return s
|
||||
|
||||
+122
-46
@@ -89,6 +89,11 @@ type Prim = {
|
||||
}
|
||||
type Section = { object: string?, group: string?, prims: { Prim }, byKey: { [string]: Prim }, smoothing: string? }
|
||||
|
||||
local TOK = "[ \t]+([^%s#\\]+)"
|
||||
local V2 = "^" .. TOK .. TOK .. "[ \t]*\r?\n()"
|
||||
local V3 = "^" .. TOK .. TOK .. TOK .. "[ \t]*\r?\n()"
|
||||
local V4 = "^" .. TOK .. TOK .. TOK .. TOK .. "[ \t]*\r?\n()"
|
||||
|
||||
function Obj.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?)
|
||||
local triangulate = not (opts and opts.triangulate == false)
|
||||
local flipV = not (opts and opts.flipV == false)
|
||||
@@ -164,7 +169,117 @@ function Obj.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.E
|
||||
return vi, ti, ni
|
||||
end
|
||||
local fs: { string } = {}
|
||||
local SV, ST, SN = {}, {}, {}
|
||||
local function element(key: string, k: number): Err.Err?
|
||||
local mode = if key == "f" then (if triangulate then "triangles" else "polygons") elseif key == "l" then "lines" else "points"
|
||||
if (key == "f" and k < 3) or (key == "l" and k < 2) or k < 1 then
|
||||
return Err.new(Err.CORRUPT, "an element with too few corners on line " .. lineNo)
|
||||
end
|
||||
corners += k
|
||||
if corners > maxV * 4 then
|
||||
return Err.new(Err.LIMIT, "too many face corners")
|
||||
end
|
||||
local p = prim(mode)
|
||||
for i = 1, k do
|
||||
local tok = fs[i]
|
||||
local vi, ti, ni = corner(tok)
|
||||
if not vi then
|
||||
return Err.new(Err.CORRUPT, "bad index '" .. tok .. "' on line " .. lineNo)
|
||||
end
|
||||
SV[i], ST[i], SN[i] = vi, ti, ni
|
||||
if ti >= 0 then
|
||||
p.hasT = true
|
||||
end
|
||||
if ni >= 0 then
|
||||
p.hasN = true
|
||||
end
|
||||
end
|
||||
local cv, ct, cn = p.cv, p.ct, p.cn
|
||||
local o = #cv
|
||||
if mode == "triangles" then
|
||||
for a = 2, k - 1 do
|
||||
cv[o + 1], ct[o + 1], cn[o + 1] = SV[1], ST[1], SN[1]
|
||||
cv[o + 2], ct[o + 2], cn[o + 2] = SV[a], ST[a], SN[a]
|
||||
cv[o + 3], ct[o + 3], cn[o + 3] = SV[a + 1], ST[a + 1], SN[a + 1]
|
||||
o += 3
|
||||
end
|
||||
elseif mode == "lines" then
|
||||
for a = 1, k - 1 do
|
||||
cv[o + 1], ct[o + 1], cn[o + 1] = SV[a], ST[a], SN[a]
|
||||
cv[o + 2], ct[o + 2], cn[o + 2] = SV[a + 1], ST[a + 1], SN[a + 1]
|
||||
o += 2
|
||||
end
|
||||
else
|
||||
for i = 1, k do
|
||||
cv[o + i], ct[o + i], cn[o + i] = SV[i], ST[i], SN[i]
|
||||
end
|
||||
if mode == "polygons" then
|
||||
table.insert(p.faces, k)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
while pos <= len do
|
||||
-- plain "v x y z", "vt u v", "vn x y z" and three- / four-corner "f" lines; anything else takes the general path
|
||||
local c0 = string.byte(text, pos)
|
||||
if c0 == 118 then -- v
|
||||
local c1 = string.byte(text, pos + 1)
|
||||
if c1 == 32 or c1 == 9 then
|
||||
local x, y, z, ne = string.match(text, V3, pos + 1)
|
||||
if x then
|
||||
local fx, fy, fz = tonumber(x), tonumber(y), tonumber(z)
|
||||
if fx and fy and fz and np < maxV then
|
||||
P[np * 3 + 1], P[np * 3 + 2], P[np * 3 + 3] = fx, fy, fz
|
||||
np += 1
|
||||
lineNo += 1
|
||||
pos = ne
|
||||
continue
|
||||
end
|
||||
end
|
||||
elseif c1 == 110 then -- vn
|
||||
local x, y, z, ne = string.match(text, V3, pos + 2)
|
||||
if x then
|
||||
local fx, fy, fz = tonumber(x), tonumber(y), tonumber(z)
|
||||
if fx and fy and fz and nn < maxV then
|
||||
N[nn * 3 + 1], N[nn * 3 + 2], N[nn * 3 + 3] = fx, fy, fz
|
||||
nn += 1
|
||||
lineNo += 1
|
||||
pos = ne
|
||||
continue
|
||||
end
|
||||
end
|
||||
elseif c1 == 116 then -- vt
|
||||
local u, v, ne = string.match(text, V2, pos + 2)
|
||||
if u then
|
||||
local fu, fv = tonumber(u), tonumber(v)
|
||||
if fu and fv and nt < maxV then
|
||||
UV[nt * 2 + 1], UV[nt * 2 + 2] = fu, if flipV then 1 - fv else fv
|
||||
nt += 1
|
||||
lineNo += 1
|
||||
pos = ne
|
||||
continue
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif c0 == 102 then -- f
|
||||
local a, b, c, ne = string.match(text, V3, pos + 1)
|
||||
local k = 3
|
||||
local d = nil
|
||||
if not a then
|
||||
a, b, c, d, ne = string.match(text, V4, pos + 1)
|
||||
k = 4
|
||||
end
|
||||
if a then
|
||||
fs[1], fs[2], fs[3], fs[4] = a, b, c, d
|
||||
lineNo += 1
|
||||
local err = element("f", k)
|
||||
if err then
|
||||
return nil, err
|
||||
end
|
||||
pos = ne
|
||||
continue
|
||||
end
|
||||
end
|
||||
local e = string.find(text, "\n", pos, true) or (len + 1)
|
||||
local line = string.sub(text, pos, e - 1)
|
||||
pos = e + 1
|
||||
@@ -229,50 +344,9 @@ function Obj.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.E
|
||||
for tok in string.gmatch(rest, "%S+") do
|
||||
table.insert(fs, tok)
|
||||
end
|
||||
local k = #fs
|
||||
local mode = if key == "f" then (if triangulate then "triangles" else "polygons") elseif key == "l" then "lines" else "points"
|
||||
if (key == "f" and k < 3) or (key == "l" and k < 2) or k < 1 then
|
||||
return nil, Err.new(Err.CORRUPT, "an element with too few corners on line " .. lineNo)
|
||||
end
|
||||
corners += k
|
||||
if corners > maxV * 4 then
|
||||
return nil, Err.new(Err.LIMIT, "too many face corners")
|
||||
end
|
||||
local p = prim(mode)
|
||||
local base = #p.cv
|
||||
for i, tok in fs do
|
||||
local vi, ti, ni = corner(tok)
|
||||
if not vi then
|
||||
return nil, Err.new(Err.CORRUPT, "bad index '" .. tok .. "' on line " .. lineNo)
|
||||
end
|
||||
p.cv[base + i], p.ct[base + i], p.cn[base + i] = vi, ti, ni
|
||||
if ti >= 0 then
|
||||
p.hasT = true
|
||||
end
|
||||
if ni >= 0 then
|
||||
p.hasN = true
|
||||
end
|
||||
end
|
||||
if mode == "triangles" and k > 3 then
|
||||
local cv, ct, cn = table.move(p.cv, base + 1, base + k, 1, {}), table.move(p.ct, base + 1, base + k, 1, {}), table.move(p.cn, base + 1, base + k, 1, {})
|
||||
local o = base
|
||||
for a = 2, k - 1 do
|
||||
for _, j in { 1, a, a + 1 } do
|
||||
o += 1
|
||||
p.cv[o], p.ct[o], p.cn[o] = cv[j], ct[j], cn[j]
|
||||
end
|
||||
end
|
||||
elseif mode == "lines" then
|
||||
local cv, ct, cn = table.move(p.cv, base + 1, base + k, 1, {}), table.move(p.ct, base + 1, base + k, 1, {}), table.move(p.cn, base + 1, base + k, 1, {})
|
||||
local o = base
|
||||
for a = 1, k - 1 do
|
||||
for _, j in { a, a + 1 } do
|
||||
o += 1
|
||||
p.cv[o], p.ct[o], p.cn[o] = cv[j], ct[j], cn[j]
|
||||
end
|
||||
end
|
||||
elseif mode == "polygons" then
|
||||
table.insert(p.faces, k)
|
||||
local err = element(key, #fs)
|
||||
if err then
|
||||
return nil, err
|
||||
end
|
||||
elseif key == "o" then
|
||||
object = rest
|
||||
@@ -471,6 +545,7 @@ end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ encode
|
||||
local probe = buffer.create(4)
|
||||
local F32_FORMATS = { "%.6g", "%.7g", "%.8g" }
|
||||
local function f32str(v: number): string
|
||||
if v ~= v or v == math.huge or v == -math.huge then
|
||||
return "0"
|
||||
@@ -480,7 +555,7 @@ local function f32str(v: number): string
|
||||
end
|
||||
buffer.writef32(probe, 0, v)
|
||||
local want = buffer.readf32(probe, 0)
|
||||
for _, f in { "%.6g", "%.7g", "%.8g" } do
|
||||
for _, f in F32_FORMATS do
|
||||
local s = string.format(f, v)
|
||||
buffer.writef32(probe, 0, tonumber(s) :: number)
|
||||
if buffer.readf32(probe, 0) == want then
|
||||
@@ -658,7 +733,8 @@ function Obj.encode(scene: Types.Scene, opts: EncodeOptions?): (buffer?, Err.Err
|
||||
local mode = prim.mode or "triangles"
|
||||
if mode == "triangles" then
|
||||
for t = 0, count // 3 - 1 do
|
||||
face({ at(t * 3), at(t * 3 + 1), at(t * 3 + 2) })
|
||||
local a, b, c = ref(at(t * 3)), ref(at(t * 3 + 1)), ref(at(t * 3 + 2))
|
||||
table.insert(out, if mirror then "f " .. c .. " " .. b .. " " .. a else "f " .. a .. " " .. b .. " " .. c)
|
||||
end
|
||||
elseif mode == "polygons" then
|
||||
local F = if prim.faces then Types.Scene.reader(prim.faces) else nil
|
||||
|
||||
@@ -244,12 +244,13 @@ function Rbxm.decode(r: Bytes.Reader, opts: DecodeOptions?): (Rbx.Tree?, Err.Err
|
||||
local vals, msg = Binary.decode(t, body, q + 1, be, n, ctx)
|
||||
if vals then
|
||||
local tname = Rbx.TYPE_NAMES[t]
|
||||
for i, ref in cls.refs do
|
||||
local inst = byRef[ref]
|
||||
if pname == "Name" and t == 0x01 then
|
||||
inst.name = vals[i]
|
||||
else
|
||||
inst.properties[pname] = { type = tname, value = vals[i] }
|
||||
if pname == "Name" and t == 0x01 then
|
||||
for i, ref in cls.refs do
|
||||
byRef[ref].name = vals[i]
|
||||
end
|
||||
else
|
||||
for i, ref in cls.refs do
|
||||
byRef[ref].properties[pname] = { type = tname, value = vals[i] }
|
||||
end
|
||||
end
|
||||
elseif msg == "unknown" then
|
||||
@@ -322,7 +323,7 @@ local function columnType(insts: { Rbx.Instance }, pname: string): (number?, str
|
||||
local id, tname = nil, nil
|
||||
for _, inst in insts do
|
||||
local v = inst.properties[pname]
|
||||
if v then
|
||||
if v and (type(v) ~= "table" or tname == nil or v.type ~= tname) then
|
||||
if type(v) ~= "table" or type(v.type) ~= "string" then
|
||||
return nil, "property " .. pname .. " of " .. inst.className .. " is not a { type, value } table"
|
||||
end
|
||||
|
||||
@@ -81,6 +81,10 @@ local function num(s: string?): number
|
||||
if s == nil then
|
||||
return 0
|
||||
end
|
||||
local v = tonumber(s)
|
||||
if v then
|
||||
return v
|
||||
end
|
||||
local t = string.lower((string.gsub(s, "^%s+", "")))
|
||||
t = string.gsub(t, "%s+$", "")
|
||||
if t == "inf" or t == "+inf" or t == "infinity" then
|
||||
@@ -100,8 +104,27 @@ end
|
||||
local function comps(node: Xml.Node?, names: { string }): { number }
|
||||
local out = table.create(#names, 0)
|
||||
if node then
|
||||
-- the children in order, element i usually named names[i]
|
||||
local kids = node.children
|
||||
local k = 1
|
||||
for i, n in names do
|
||||
out[i] = num(childText(node, n))
|
||||
local c = nil
|
||||
while k <= #kids do
|
||||
local ch = kids[k]
|
||||
if type(ch) == "table" then
|
||||
if ch.name == n then
|
||||
c = ch
|
||||
end
|
||||
break
|
||||
end
|
||||
k += 1
|
||||
end
|
||||
if c then
|
||||
k += 1
|
||||
else
|
||||
c = Xml.child(node, n)
|
||||
end
|
||||
out[i] = num(if c then Xml.text(c) else nil)
|
||||
end
|
||||
end
|
||||
return out
|
||||
@@ -117,10 +140,10 @@ end
|
||||
local CF_NAMES = { "X", "Y", "Z", "R00", "R01", "R02", "R10", "R11", "R12", "R20", "R21", "R22" }
|
||||
local PHYS_NAMES = { "Density", "Friction", "Elasticity", "FrictionWeight", "ElasticityWeight" }
|
||||
|
||||
local function readRaw(node: Xml.Node, shared: { [string]: string }, key: string): (string, any)
|
||||
local function readRaw(node: Xml.Node, shared: { [string]: string }, cls: string, pname: string): (string, any)
|
||||
local tag = node.name
|
||||
local scalar = SCALAR_TAGS[tag]
|
||||
if tag == "int" and BRICKCOLOR[key] then
|
||||
if tag == "int" and BRICKCOLOR[cls .. "." .. pname] then
|
||||
scalar = "BrickColor"
|
||||
end
|
||||
if scalar then
|
||||
@@ -264,8 +287,8 @@ local function round32(v: any, which: any): any
|
||||
end
|
||||
return v
|
||||
end
|
||||
local function readValue(node: Xml.Node, shared: { [string]: string }, key: string): (string, any)
|
||||
local t, v = readRaw(node, shared, key)
|
||||
local function readValue(node: Xml.Node, shared: { [string]: string }, cls: string, pname: string): (string, any)
|
||||
local t, v = readRaw(node, shared, cls, pname)
|
||||
local which = F32[t]
|
||||
if which then
|
||||
v = round32(v, which)
|
||||
@@ -316,7 +339,7 @@ function Rbxmx.decode(r: Bytes.Reader, opts: DecodeOptions?): (Rbx.Tree?, Err.Er
|
||||
if type(pnode) == "table" and string.sub(pnode.name, 1, 1) ~= "#" then
|
||||
local pname = pnode.attrs.name
|
||||
if type(pname) == "string" then
|
||||
local t, v = readValue(pnode, shared, cls .. "." .. pname)
|
||||
local t, v = readValue(pnode, shared, cls, pname)
|
||||
if pname == "Name" and (t == "String" or t == "ProtectedString") then
|
||||
inst.name = v
|
||||
else
|
||||
|
||||
@@ -438,11 +438,16 @@ function MeshOps.computeNormals(prim: Primitive, opts: { flat: boolean? }?): (Pr
|
||||
local e2x, e2y, e2z = readf32(pd, c * 12) - ax, readf32(pd, c * 12 + 4) - ay, readf32(pd, c * 12 + 8) - az
|
||||
-- the cross product is twice the area times the unit normal: area weighting for free
|
||||
local nx, ny, nz = e1y * e2z - e1z * e2y, e1z * e2x - e1x * e2z, e1x * e2y - e1y * e2x
|
||||
for _, v in { a, b, c } do
|
||||
acc[v * 3 + 1] += nx
|
||||
acc[v * 3 + 2] += ny
|
||||
acc[v * 3 + 3] += nz
|
||||
end
|
||||
a, b, c = a * 3, b * 3, c * 3
|
||||
acc[a + 1] += nx
|
||||
acc[a + 2] += ny
|
||||
acc[a + 3] += nz
|
||||
acc[b + 1] += nx
|
||||
acc[b + 2] += ny
|
||||
acc[b + 3] += nz
|
||||
acc[c + 1] += nx
|
||||
acc[c + 2] += ny
|
||||
acc[c + 3] += nz
|
||||
end
|
||||
local out = buffer.create(nv * 12)
|
||||
for v = 0, nv - 1 do
|
||||
@@ -500,14 +505,25 @@ function MeshOps.computeTangents(prim: Primitive, opts: { texCoord: number? }?):
|
||||
local r = 1 / den
|
||||
local tx, ty, tz = (t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r
|
||||
local bx, by, bz = (s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r
|
||||
for _, v in { a, b, c } do
|
||||
tan[v * 3 + 1] += tx
|
||||
tan[v * 3 + 2] += ty
|
||||
tan[v * 3 + 3] += tz
|
||||
bit[v * 3 + 1] += bx
|
||||
bit[v * 3 + 2] += by
|
||||
bit[v * 3 + 3] += bz
|
||||
end
|
||||
local a3, b3, c3 = a * 3, b * 3, c * 3
|
||||
tan[a3 + 1] += tx
|
||||
tan[a3 + 2] += ty
|
||||
tan[a3 + 3] += tz
|
||||
bit[a3 + 1] += bx
|
||||
bit[a3 + 2] += by
|
||||
bit[a3 + 3] += bz
|
||||
tan[b3 + 1] += tx
|
||||
tan[b3 + 2] += ty
|
||||
tan[b3 + 3] += tz
|
||||
bit[b3 + 1] += bx
|
||||
bit[b3 + 2] += by
|
||||
bit[b3 + 3] += bz
|
||||
tan[c3 + 1] += tx
|
||||
tan[c3 + 2] += ty
|
||||
tan[c3 + 3] += tz
|
||||
bit[c3 + 1] += bx
|
||||
bit[c3 + 2] += by
|
||||
bit[c3 + 3] += bz
|
||||
end
|
||||
end
|
||||
local out = buffer.create(nv * 16)
|
||||
|
||||
@@ -47,27 +47,35 @@ local CODEC: { [string]: string } = {
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ sniff
|
||||
-- 188 or 192 (M2TS): three sync bytes a packet apart (fewer in a short file) within the first 2 KB
|
||||
local SIZES = { 188, 192 }
|
||||
local function packetSize(r: Bytes.Reader): (number, number)
|
||||
local n = r:remaining()
|
||||
for start = 0, math.min(n, 2048) - 1 do
|
||||
if r:peekU8(start) == 0x47 then
|
||||
for _, size in { 188, 192 } do
|
||||
local hits, need = 0, math.min(3, (n - start - 1) // size + 1)
|
||||
for k = 0, 2 do
|
||||
local at = start + k * size
|
||||
if at < n and r:peekU8(at) == 0x47 then
|
||||
hits += 1
|
||||
end
|
||||
local head = r:peek(2048 + 2 * 192)
|
||||
local lim = math.min(n, 2048)
|
||||
local start = 0
|
||||
while start < lim do
|
||||
local f = string.find(head, "G", start + 1, true) -- 0x47
|
||||
if not f or f > lim then
|
||||
break
|
||||
end
|
||||
start = f - 1
|
||||
for _, size in SIZES do
|
||||
local hits, need = 0, math.min(3, (n - start - 1) // size + 1)
|
||||
for k = 0, 2 do
|
||||
local at = start + k * size
|
||||
if at < n and string.byte(head, at + 1) == 0x47 then
|
||||
hits += 1
|
||||
end
|
||||
if hits >= need and (need >= 2 or start == 0) then
|
||||
if size == 192 and start >= 4 then
|
||||
return 192, start - 4
|
||||
elseif size == 188 then
|
||||
return 188, start
|
||||
end
|
||||
end
|
||||
if hits >= need and (need >= 2 or start == 0) then
|
||||
if size == 192 and start >= 4 then
|
||||
return 192, start - 4
|
||||
elseif size == 188 then
|
||||
return 188, start
|
||||
end
|
||||
end
|
||||
end
|
||||
start += 1
|
||||
end
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
+12
-2
@@ -1,9 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
# Timings (bash tools/bench.sh): tools/bench.luau under luau --codegen -O2 and under LuaJIT (the module build, build/_modules/luajit).
|
||||
# Timings (bash tools/bench.sh [core [filter]]): tools/bench.luau under luau --codegen -O2 and under LuaJIT (the module build,
|
||||
# build/_modules/luajit). "core" runs tools/bench_core.luau (inflate / deflate, checksums, rbxm / rbxmx, json / xml,
|
||||
# F.detect, gltf / obj, the other decompressors) under luau -O2, luau --codegen -O2 and LuaJIT; a filter keeps the lines
|
||||
# whose label contains it.
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
LUAU=${LUAU:-$(command -v luau || nix shell nixpkgs#luau -c sh -c 'command -v luau')}
|
||||
LUAJIT=${LUAJIT:-$(command -v luajit || nix shell nixpkgs#luajit -c sh -c 'command -v luajit')}
|
||||
python3 -I tools/fixtures.py > /dev/null || exit 1
|
||||
python3 -I tools/build.py luajit > /dev/null || exit 1
|
||||
LJPATH='package.path = "build/_modules/luajit/?.lua;build/_modules/luajit/?/init.lua;" .. package.path'
|
||||
if [ "$1" = core ]; then
|
||||
"$LUAU" -O2 tools/bench_core.luau -a "$2"
|
||||
"$LUAU" --codegen -O2 tools/bench_core.luau -a "$2"
|
||||
"$LUAJIT" -e "$LJPATH" build/_modules/luajit/tools/bench_core.lua "$2"
|
||||
exit 0
|
||||
fi
|
||||
"$LUAU" --codegen -O2 tools/bench.luau
|
||||
"$LUAJIT" -e 'package.path = "build/_modules/luajit/?.lua;build/_modules/luajit/?/init.lua;" .. package.path' build/_modules/luajit/tools/bench.lua
|
||||
"$LUAJIT" -e "$LJPATH" build/_modules/luajit/tools/bench.lua
|
||||
@@ -0,0 +1,285 @@
|
||||
-- Throughput of the core codecs (bash tools/bench.sh core): inflate / deflate, checksums, rbxm / rbxmx, json / xml,
|
||||
-- F.detect, gltf / obj and the other compressors. MB/s are of the decoded side, best of n runs.
|
||||
local Deflate = require("@rosetta/codecs/compress/Deflate")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Adler32 = require("@rosetta/core/Adler32")
|
||||
local Base64 = require("@rosetta/core/Base64")
|
||||
local Md5 = require("@rosetta/core/Md5")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Types = require("@rosetta/Types")
|
||||
local B = require("@tests/gen/deflate_bench")
|
||||
|
||||
local runtime = if (_G :: any).jit ~= nil then "luajit" else "luau"
|
||||
local filter: string? = (...) :: any
|
||||
if filter == "" then
|
||||
filter = nil
|
||||
end
|
||||
|
||||
local function want(labels: string): boolean
|
||||
return filter == nil or string.find(labels, filter :: string, 1, true) ~= nil
|
||||
end
|
||||
|
||||
local function bench(label: string, n: number, bytes: number, f: () -> ())
|
||||
if filter and not string.find(label, filter, 1, true) then
|
||||
return 0
|
||||
end
|
||||
f()
|
||||
local dt, spent, i = math.huge, 0, 0
|
||||
while i < n or (spent < 1.5 and i < 40) do -- best of n, and of at least 1.5 s: the machine is shared
|
||||
local t0 = os.clock()
|
||||
f()
|
||||
local d = os.clock() - t0
|
||||
dt, spent, i = math.min(dt, d), spent + d, i + 1
|
||||
end
|
||||
print(string.format("%-8s %-36s %8.2f ms %7.1f MB/s", runtime, label, dt * 1000, bytes / dt / 1e6))
|
||||
return dt
|
||||
end
|
||||
|
||||
local z = buffer.fromstring(B.zlib)
|
||||
local g = buffer.fromstring(B.gzip)
|
||||
local out = assert(Deflate.zlib(z))
|
||||
assert(buffer.len(out) == B.size and Crc32.of(out) == B.crc, "bench corpus mismatch")
|
||||
bench("inflate (growing output)", 5, B.size, function()
|
||||
Deflate.inflate(z, 2, buffer.len(z) - 6)
|
||||
end)
|
||||
bench("inflate (exact size)", 5, B.size, function()
|
||||
Deflate.inflate(z, 2, buffer.len(z) - 6, B.size)
|
||||
end)
|
||||
bench("zlib (+ adler32)", 5, B.size, function()
|
||||
Deflate.zlib(z)
|
||||
end)
|
||||
bench("gunzip (+ crc32)", 5, B.size, function()
|
||||
Deflate.gunzip(g)
|
||||
end)
|
||||
bench("crc32", 10, B.size, function()
|
||||
Crc32.of(out)
|
||||
end)
|
||||
bench("adler32", 10, B.size, function()
|
||||
Adler32.of(out)
|
||||
end)
|
||||
if want("compress -6 text compress -1 text compress -6 f32 inflate f32") then
|
||||
local part = buffer.create(1500000)
|
||||
buffer.copy(part, 0, out, 0, 1500000)
|
||||
local c6 = assert(Deflate.compress(part, { level = 6 }))
|
||||
bench("compress -6 text (1.5 MB in)", 2, 1500000, function()
|
||||
Deflate.compress(part, { level = 6 })
|
||||
end)
|
||||
bench("compress -1 text (1.5 MB in)", 2, 1500000, function()
|
||||
Deflate.compress(part, { level = 1 })
|
||||
end)
|
||||
-- f32 vertex data: a smooth surface sampled on a grid (positions, normals, uvs), as glTF / mesh writers emit
|
||||
local N = 180
|
||||
local fl = buffer.create(N * N * 32)
|
||||
for y = 0, N - 1 do
|
||||
for x = 0, N - 1 do
|
||||
local o = (y * N + x) * 32
|
||||
local h = math.sin(x * 0.07) * math.cos(y * 0.05) * 3
|
||||
buffer.writef32(fl, o, x * 0.25)
|
||||
buffer.writef32(fl, o + 4, h)
|
||||
buffer.writef32(fl, o + 8, y * 0.25)
|
||||
buffer.writef32(fl, o + 12, -math.cos(x * 0.07) * 0.2)
|
||||
buffer.writef32(fl, o + 16, 0.97)
|
||||
buffer.writef32(fl, o + 20, math.sin(y * 0.05) * 0.15)
|
||||
buffer.writef32(fl, o + 24, x / N)
|
||||
buffer.writef32(fl, o + 28, y / N)
|
||||
end
|
||||
end
|
||||
local cf = assert(Deflate.compress(fl, { level = 6 }))
|
||||
bench("compress -6 f32 (" .. buffer.len(fl) // 1000 .. " KB in)", 2, buffer.len(fl), function()
|
||||
Deflate.compress(fl, { level = 6 })
|
||||
end)
|
||||
bench("inflate f32", 5, buffer.len(fl), function()
|
||||
Deflate.inflate(cf, 0, buffer.len(cf))
|
||||
end)
|
||||
if not filter then
|
||||
print(string.format("%-8s compress -6 sizes: text %d (zlib -6 ref %s), f32 %d", runtime, buffer.len(c6), tostring((B :: any).z6 or "?"), buffer.len(cf)))
|
||||
end
|
||||
end
|
||||
if want("base64 encode base64 decode md5") then
|
||||
local s = buffer.create(3000000)
|
||||
buffer.copy(s, 0, out, 0, 3000000)
|
||||
local enc = Base64.encode(s)
|
||||
bench("base64 encode", 5, 3000000, function()
|
||||
Base64.encode(s)
|
||||
end)
|
||||
bench("base64 decode", 5, 3000000, function()
|
||||
Base64.decode(enc)
|
||||
end)
|
||||
bench("md5", 5, 3000000, function()
|
||||
Md5.of(s)
|
||||
end)
|
||||
end
|
||||
if want("rbxm decode rbxm encode rbxmx decode rbxmx encode") then
|
||||
local Rbx = require("@rosetta/codecs/model/Rbx")
|
||||
local Rbxm = require("@rosetta/model/rbxm")
|
||||
local Rbxmx = require("@rosetta/model/rbxmx")
|
||||
local tree = Rbx.tree()
|
||||
local folder = Rbx.add(tree, Rbx.instance("Folder", "Parts"))
|
||||
for i = 1, 20000 do
|
||||
local p = Rbx.add(folder, Rbx.instance("Part", "P" .. i))
|
||||
Rbx.set(p, "CFrame", "CFrame", { i, i % 7, -i, 1, 0, 0, 0, 1, 0, 0, 0, 1 })
|
||||
Rbx.set(p, "size", "Vector3", { 4, 1, 2 + i % 3 })
|
||||
Rbx.set(p, "Color3uint8", "Color3uint8", { i % 256, 128, 255 - i % 256 })
|
||||
Rbx.set(p, "Anchored", "Bool", i % 2 == 0)
|
||||
Rbx.set(p, "Transparency", "Float32", (i % 4) / 4)
|
||||
Rbx.set(p, "Material", "Enum", 256)
|
||||
end
|
||||
local bin = Rbxm.encode(tree) :: buffer
|
||||
local xml = Rbxmx.encode(tree) :: buffer
|
||||
bench("rbxm decode (20k parts)", 3, buffer.len(bin), function()
|
||||
Rbxm.decode(Bytes.reader(bin))
|
||||
end)
|
||||
bench("rbxm encode (20k parts)", 3, buffer.len(bin), function()
|
||||
Rbxm.encode(tree)
|
||||
end)
|
||||
bench("rbxmx decode (20k parts)", 3, buffer.len(xml), function()
|
||||
Rbxmx.decode(Bytes.reader(xml))
|
||||
end)
|
||||
bench("rbxmx encode (20k parts)", 3, buffer.len(xml), function()
|
||||
Rbxmx.encode(tree)
|
||||
end)
|
||||
end
|
||||
if want("json decode (indented) json decode (compact) json encode") then
|
||||
local Json = require("@rosetta/codecs/text/Json")
|
||||
local JB = require("@tests/gen/json_bench")
|
||||
local v = assert(Json.decode(JB.text))
|
||||
bench("json decode (indented)", 5, #JB.text, function()
|
||||
Json.decode(JB.text)
|
||||
end)
|
||||
bench("json decode (compact)", 5, #JB.compact, function()
|
||||
Json.decode(JB.compact)
|
||||
end)
|
||||
bench("json encode (compact, sorted)", 5, #JB.compact, function()
|
||||
Json.encode(v)
|
||||
end)
|
||||
end
|
||||
if want("xml decode (DOM) xml events xml encode") then
|
||||
local Xml = require("@rosetta/codecs/text/Xml")
|
||||
local XB = require("@tests/gen/xml_bench")
|
||||
local doc = assert(Xml.decode(XB.text))
|
||||
bench("xml decode (DOM)", 5, #XB.text, function()
|
||||
Xml.decode(XB.text)
|
||||
end)
|
||||
bench("xml events", 5, #XB.text, function()
|
||||
for _ in Xml.events(XB.text) do
|
||||
end
|
||||
end)
|
||||
bench("xml encode", 5, #XB.text, function()
|
||||
Xml.encode(doc)
|
||||
end)
|
||||
end
|
||||
if want("F.detect png F.detect unknown") then
|
||||
-- F.detect: content sniffing over every registered format (MB/s here = thousands of detects per second)
|
||||
local F = require("@rosetta")
|
||||
local PB = require("@tests/gen/png_bench")
|
||||
local png = buffer.fromstring(PB[1].data)
|
||||
local junk = buffer.create(4096)
|
||||
for i = 0, 4095 do
|
||||
buffer.writeu8(junk, i, (i * 7919) % 251)
|
||||
end
|
||||
local t0 = os.clock()
|
||||
F.detect(junk)
|
||||
if not filter then
|
||||
print(string.format("%-8s %-36s %8.2f ms", runtime, "F.detect first call (loads modules)", (os.clock() - t0) * 1000))
|
||||
end
|
||||
bench("F.detect png (k/s)", 5, 1000, function()
|
||||
for _ = 1, 100 do
|
||||
F.detect(png)
|
||||
end
|
||||
end)
|
||||
bench("F.detect png + name (k/s)", 5, 1000, function()
|
||||
for _ = 1, 100 do
|
||||
F.detect(png, { name = "a.png" })
|
||||
end
|
||||
end)
|
||||
bench("F.detect unknown (k/s)", 5, 1000, function()
|
||||
for _ = 1, 100 do
|
||||
F.detect(junk)
|
||||
end
|
||||
end)
|
||||
end
|
||||
if want("meshops computeNormals gltf glb decode gltf glb encode gltf json+base64 decode obj decode obj encode") then
|
||||
local MeshOps = require("@rosetta/ops/MeshOps")
|
||||
local Gltf = require("@rosetta/model/gltf")
|
||||
local Obj = require("@rosetta/model/obj")
|
||||
local N = 400
|
||||
local pos = Types.Scene.accessor(nil, "f32", 3, N * N)
|
||||
local uv = Types.Scene.accessor(nil, "f32", 2, N * N)
|
||||
for y = 0, N - 1 do
|
||||
for x = 0, N - 1 do
|
||||
local i = y * N + x
|
||||
buffer.writef32(pos.data, i * 12, x / N)
|
||||
buffer.writef32(pos.data, i * 12 + 4, math.sin(x * 0.1) * math.cos(y * 0.1) * 0.05)
|
||||
buffer.writef32(pos.data, i * 12 + 8, y / N)
|
||||
buffer.writef32(uv.data, i * 8, x / N)
|
||||
buffer.writef32(uv.data, i * 8 + 4, y / N)
|
||||
end
|
||||
end
|
||||
local ind = Types.Scene.accessor(nil, "u32", 1, (N - 1) * (N - 1) * 6)
|
||||
local k = 0
|
||||
for y = 0, N - 2 do
|
||||
for x = 0, N - 2 do
|
||||
local a = y * N + x
|
||||
for _, v in { a, a + N, a + 1, a + 1, a + N, a + N + 1 } do
|
||||
buffer.writeu32(ind.data, k * 4, v)
|
||||
k += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
local prim = { attributes = { POSITION = pos, TEXCOORD_0 = uv }, indices = ind, mode = "triangles" } :: any
|
||||
MeshOps.computeNormals(prim)
|
||||
local scene = Types.Scene.fromPrimitive(prim, "grid")
|
||||
bench("meshops computeNormals 318k tris", 3, buffer.len(pos.data), function()
|
||||
MeshOps.computeNormals(prim)
|
||||
end)
|
||||
local glb = assert(Gltf.encode(scene, { binary = true }))
|
||||
bench("gltf glb decode", 5, buffer.len(glb), function()
|
||||
Gltf.decode(Bytes.reader(glb))
|
||||
end)
|
||||
bench("gltf glb encode", 3, buffer.len(glb), function()
|
||||
Gltf.encode(scene, { binary = true })
|
||||
end)
|
||||
local gltf = assert(Gltf.encode(scene, { binary = false }))
|
||||
bench("gltf json+base64 decode", 3, buffer.len(gltf), function()
|
||||
Gltf.decode(Bytes.reader(gltf))
|
||||
end)
|
||||
local obj = assert(Obj.encode(scene))
|
||||
bench("obj decode", 2, buffer.len(obj), function()
|
||||
Obj.decode(Bytes.reader(obj))
|
||||
end)
|
||||
bench("obj encode", 2, buffer.len(obj), function()
|
||||
Obj.encode(scene)
|
||||
end)
|
||||
end
|
||||
if want("zstd -3 lz4 block brotli bzip2 xz -6") then
|
||||
local Zstd = require("@rosetta/codecs/compress/Zstd")
|
||||
local ZB = require("@tests/gen/zstd_bench")
|
||||
local z3 = buffer.fromstring(ZB.data3)
|
||||
bench("zstd -3 (no checksum)", 3, ZB.size, function()
|
||||
Zstd.decompress(z3, nil, nil, { verify = false })
|
||||
end)
|
||||
local Lz4 = require("@rosetta/codecs/compress/Lz4")
|
||||
local LB = require("@tests/gen/lz4_bench")
|
||||
local lz = buffer.fromstring(LB.data)
|
||||
bench("lz4 block decompress (hc9)", 5, LB.size, function()
|
||||
Lz4.decompress(lz, nil, nil, LB.size)
|
||||
end)
|
||||
local Brotli = require("@rosetta/codecs/compress/Brotli")
|
||||
local BB = require("@tests/gen/brotli_bench")
|
||||
local bz = buffer.fromstring(BB.data)
|
||||
bench("brotli decompress (q9 w22)", 3, BB.size, function()
|
||||
Brotli.decompress(bz)
|
||||
end)
|
||||
local Bzip2 = require("@rosetta/codecs/compress/Bzip2")
|
||||
local BZ = require("@tests/gen/bzip2_bench")
|
||||
local b2 = buffer.fromstring(BZ.data)
|
||||
bench("bzip2 decompress -9", 3, BZ.size, function()
|
||||
Bzip2.decompress(b2)
|
||||
end)
|
||||
local Lzma = require("@rosetta/codecs/compress/Lzma")
|
||||
local XB = require("@tests/gen/lzma_bench")
|
||||
local lx = buffer.fromstring(XB.xz)
|
||||
bench("xz -6 (lzma2 + crc64)", 3, XB.size, function()
|
||||
Lzma.xz(lx)
|
||||
end)
|
||||
end
|
||||
@@ -1 +1 @@
|
||||
92
|
||||
91
|
||||
Reference in new issue
Block a user