Implemented FastNumericPeekPoke

This commit is contained in:
2026-11-05 07:32:34 +01:00
parent ea38a45cf3
commit 8bd7ffa74c
10 changed files with 74 additions and 63 deletions
+3
View File
@@ -1,3 +1,6 @@
[submodule "Includes/PB-Endianness"] [submodule "Includes/PB-Endianness"]
path = Includes/PB-Endianness path = Includes/PB-Endianness
url = https://github.com/aziascreations/PB-Endianness.git url = https://github.com/aziascreations/PB-Endianness.git
[submodule "Includes/PB-FastNumericPeekPoke"]
path = Includes/PB-FastNumericPeekPoke
url = https://github.com/aziascreations/PB-FastNumericPeekPoke.git
+1
View File
@@ -417,6 +417,7 @@ or subtract each top-level field's `MsgPackGetFieldFullSize` from the buffer's s
* `Includes/MessagePack.pbi` - Main file, only includes the others. * `Includes/MessagePack.pbi` - Main file, only includes the others.
* `Includes/_*.pbi` - One file per family. (Allocators, Literals, Primitives, Strings, ...) * `Includes/_*.pbi` - One file per family. (Allocators, Literals, Primitives, Strings, ...)
* `Includes/PB-Endianness/` - Git submodule, don't edit it from here. * `Includes/PB-Endianness/` - Git submodule, don't edit it from here.
* `Includes/PB-FastNumericPeekPoke/` - Git submodule, don't edit it from here. Use `FastPeekX()`/`FastPokeX()` instead of the numeric `PeekX()`/`PokeX()`.
* `UnitTests/` - One folder per family, numbered like the includes' order. * `UnitTests/` - One folder per family, numbered like the includes' order.
* `Examples/` - One folder per example, with a `.pb` of the same name. * `Examples/` - One folder per example, with a `.pb` of the same name.
* `PerfTests/` - Benchmarks, one folder per workload, each with a `RunPerfTests.ps1`. * `PerfTests/` - Benchmarks, one folder per workload, each with a `RunPerfTests.ps1`.
+12 -12
View File
@@ -107,16 +107,16 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteSizedFieldHeader(*MsgPackData.MsgPackDa
Select SizeFieldByteLength Select SizeFieldByteLength
Case 0 Case 0
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode | DataSize) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode | DataSize)
Case 1 Case 1
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, DataSize) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, DataSize)
Case 2 Case 2
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
PokeU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapU16(DataSize)) FastPokeU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapU16(DataSize))
Case 4 Case 4
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
PokeL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI32(DataSize)) FastPokeL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI32(DataSize))
EndSelect EndSelect
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 + SizeFieldByteLength *MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 + SizeFieldByteLength
@@ -181,7 +181,7 @@ Procedure.MsgPack_ErrorCode _MsgPackReadSizedFieldHeader(*MsgPackData.MsgPackDat
FormatCode = MsgPackGetFormatCode(*MsgPackData) FormatCode = MsgPackGetFormatCode(*MsgPackData)
If MsgPackFormatCodeToDataType(FormatCode) <> ExpectedDataType If MsgPackFormatCodeToDataType(FormatCode) <> ExpectedDataType
Debug("Unexpected format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")") Debug("Unexpected format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode *MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
ProcedureReturn #MsgPack_Error_InvalidFormatCode ProcedureReturn #MsgPack_Error_InvalidFormatCode
EndIf EndIf
@@ -227,14 +227,14 @@ Procedure.MsgPack_ErrorCode _MsgPackReadSizedFieldHeader(*MsgPackData.MsgPackDat
Case 0: Case 0:
; FixExt sizes were already set above. ; FixExt sizes were already set above.
If FormatCode = #MsgPack_FormatCode_FixStr If FormatCode = #MsgPack_FormatCode_FixStr
DataSize = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) & %00011111 DataSize = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) & %00011111
EndIf EndIf
Case 1: Case 1:
DataSize = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1) DataSize = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)
Case 2: Case 2:
DataSize = EndianSwapU16(PeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) DataSize = EndianSwapU16(FastPeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
Case 4: Case 4:
DataSize = EndianSwapI32(PeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF DataSize = EndianSwapI32(FastPeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF
EndSelect EndSelect
If Not _MsgPackHasSpaceLeft(*MsgPackData, 1 + SizeFieldByteLength + ExtTypeByteLength + DataSize) If Not _MsgPackHasSpaceLeft(*MsgPackData, 1 + SizeFieldByteLength + ExtTypeByteLength + DataSize)
+6
View File
@@ -34,6 +34,12 @@ CompilerIf Not Defined(_NibblePoker_Endianness_WasIncluded, #PB_Constant) And No
XIncludeFile "./PB-Endianness/Includes/Endianness.pbi" XIncludeFile "./PB-Endianness/Includes/Endianness.pbi"
CompilerEndIf CompilerEndIf
; Skipped if "FastNumericPeekPoke.pbi" was already included from another path, by the program or another include.
; Its procedures are only used on the C backend with "/OPTIMIZER", they alias the built-ins otherwise.
CompilerIf Not Defined(_NibblePoker_FastNumericPeekPoke_WasIncluded, #PB_Constant)
XIncludeFile "./PB-FastNumericPeekPoke/Includes/FastNumericPeekPoke.pbi"
CompilerEndIf
; ------------------------------------------------------------------------------ ; ------------------------------------------------------------------------------
+3 -3
View File
@@ -96,7 +96,7 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteExtField(*MsgPackData.MsgPackData, Form
ProcedureReturn ErrorCode ProcedureReturn ErrorCode
EndIf EndIf
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 *MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
Else Else
ErrorCode = _MsgPackWriteSizedFieldHeader(*MsgPackData, FormatCode, SizeFieldByteLength, DataSize, 1, *Data) ErrorCode = _MsgPackWriteSizedFieldHeader(*MsgPackData, FormatCode, SizeFieldByteLength, DataSize, 1, *Data)
@@ -105,7 +105,7 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteExtField(*MsgPackData.MsgPackData, Form
EndIf EndIf
EndIf EndIf
PokeB(*MsgPackData\Buffer + *MsgPackData\BufferOffset, ExtType) FastPokeB(*MsgPackData\Buffer + *MsgPackData\BufferOffset, ExtType)
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 *MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
If DataSize > 0 If DataSize > 0
@@ -133,7 +133,7 @@ Procedure.b MsgPackGetExtensionType(*MsgPackData.MsgPackData)
ProcedureReturn 0 ProcedureReturn 0
EndIf EndIf
ProcedureReturn PeekB(*MsgPackData\Buffer + *MsgPackData\BufferOffset + HeaderSize - 1) ProcedureReturn FastPeekB(*MsgPackData\Buffer + *MsgPackData\BufferOffset + HeaderSize - 1)
EndProcedure EndProcedure
+20 -20
View File
@@ -46,7 +46,7 @@ XIncludeFile "./_Binary.pbi"
; `XXX` is the format code bits and `YYYYY` the value's dynamic size. ; `XXX` is the format code bits and `YYYYY` the value's dynamic size.
; Applies to: FixStr, FixArray, FixMap ; Applies to: FixStr, FixArray, FixMap
; Remark: Doesn't apply to FixInt variants since those have their own function for extracting the value. ; Remark: Doesn't apply to FixInt variants since those have their own function for extracting the value.
Macro _MsgPackGetFieldDynamicSize_Within(MsgPackData, Mask) : (PeekA(MsgPackData\Buffer + MsgPackData\BufferOffset) & Mask) : EndMacro Macro _MsgPackGetFieldDynamicSize_Within(MsgPackData, Mask) : (FastPeekA(MsgPackData\Buffer + MsgPackData\BufferOffset) & Mask) : EndMacro
; Returns the field's dynamic size based on the byte right after the format code. ; Returns the field's dynamic size based on the byte right after the format code.
; Applies to: Str8, Bin8, Ext8 ; Applies to: Str8, Bin8, Ext8
@@ -57,7 +57,7 @@ Procedure.q _MsgPackGetFieldDynamicSize_1After(*MsgPackData.MsgPackData)
ProcedureReturn #MsgPack_InvalidSize ProcedureReturn #MsgPack_InvalidSize
EndIf EndIf
ProcedureReturn PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1) ProcedureReturn FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)
EndProcedure EndProcedure
; Returns the field's dynamic size based on the 2 bytes right after the format code. ; Returns the field's dynamic size based on the 2 bytes right after the format code.
@@ -69,7 +69,7 @@ Procedure.q _MsgPackGetFieldDynamicSize_2After(*MsgPackData.MsgPackData)
ProcedureReturn #MsgPack_InvalidSize ProcedureReturn #MsgPack_InvalidSize
EndIf EndIf
ProcedureReturn EndianSwapU(PeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) ProcedureReturn EndianSwapU(FastPeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
EndProcedure EndProcedure
; Returns the field's dynamic size based on the 4 bytes right after the format code. ; Returns the field's dynamic size based on the 4 bytes right after the format code.
@@ -81,7 +81,7 @@ Procedure.q _MsgPackGetFieldDynamicSize_4After(*MsgPackData.MsgPackData)
ProcedureReturn #MsgPack_InvalidSize ProcedureReturn #MsgPack_InvalidSize
EndIf EndIf
ProcedureReturn EndianSwapL(PeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF ProcedureReturn EndianSwapL(FastPeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF
EndProcedure EndProcedure
; Returns a given format code's spacing info based on itself and the data in the given MsgPack buffer. ; Returns a given format code's spacing info based on itself and the data in the given MsgPack buffer.
@@ -110,20 +110,20 @@ Procedure _MsgPackGetFieldSpacingInfo(*MsgPackData.MsgPackData, ExaminedDataType
Select ExaminedDataType Select ExaminedDataType
Case #MsgPack_FormatCode_FixStr: Case #MsgPack_FormatCode_FixStr:
If *VariableSizeQ <> #Null If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_Within(*MsgPackData, %00011111)) FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_Within(*MsgPackData, %00011111))
EndIf EndIf
If *ValueStartOffsetB <> #Null If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, 1) FastPokeB(*ValueStartOffsetB, 1)
EndIf EndIf
ProcedureReturn #True ProcedureReturn #True
Case #MsgPack_FormatCode_FixArray, Case #MsgPack_FormatCode_FixArray,
#MsgPack_FormatCode_FixMap: #MsgPack_FormatCode_FixMap:
If *VariableSizeQ <> #Null If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_Within(*MsgPackData, %00001111)) FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_Within(*MsgPackData, %00001111))
EndIf EndIf
If *ValueStartOffsetB <> #Null If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, 1) FastPokeB(*ValueStartOffsetB, 1)
EndIf EndIf
ProcedureReturn #True ProcedureReturn #True
@@ -132,10 +132,10 @@ Procedure _MsgPackGetFieldSpacingInfo(*MsgPackData.MsgPackData, ExaminedDataType
#MsgPack_FormatCode_Str8, #MsgPack_FormatCode_Str8,
#MsgPack_FormatCode_Bin8: #MsgPack_FormatCode_Bin8:
If *VariableSizeQ <> #Null If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_1After(*MsgPackData)) FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_1After(*MsgPackData))
EndIf EndIf
If *ValueStartOffsetB <> #Null If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, 2) FastPokeB(*ValueStartOffsetB, 2)
EndIf EndIf
ProcedureReturn #True ProcedureReturn #True
@@ -146,10 +146,10 @@ Procedure _MsgPackGetFieldSpacingInfo(*MsgPackData.MsgPackData, ExaminedDataType
#MsgPack_FormatCode_Array16, #MsgPack_FormatCode_Array16,
#MsgPack_FormatCode_Map16: #MsgPack_FormatCode_Map16:
If *VariableSizeQ <> #Null If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_2After(*MsgPackData)) FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_2After(*MsgPackData))
EndIf EndIf
If *ValueStartOffsetB <> #Null If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, 3) FastPokeB(*ValueStartOffsetB, 3)
EndIf EndIf
ProcedureReturn #True ProcedureReturn #True
@@ -160,19 +160,19 @@ Procedure _MsgPackGetFieldSpacingInfo(*MsgPackData.MsgPackData, ExaminedDataType
#MsgPack_FormatCode_Array32, #MsgPack_FormatCode_Array32,
#MsgPack_FormatCode_Map32: #MsgPack_FormatCode_Map32:
If *VariableSizeQ <> #Null If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_4After(*MsgPackData)) FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_4After(*MsgPackData))
EndIf EndIf
If *ValueStartOffsetB <> #Null If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, 5) FastPokeB(*ValueStartOffsetB, 5)
EndIf EndIf
ProcedureReturn #True ProcedureReturn #True
Default: Default:
If *VariableSizeQ <> #Null If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, #MsgPack_InvalidSize) FastPokeQ(*VariableSizeQ, #MsgPack_InvalidSize)
EndIf EndIf
If *ValueStartOffsetB <> #Null If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, #MsgPack_InvalidSize) FastPokeB(*ValueStartOffsetB, #MsgPack_InvalidSize)
EndIf EndIf
ProcedureReturn #False ProcedureReturn #False
EndSelect EndSelect
@@ -269,7 +269,7 @@ Procedure.MsgPack_ErrorCode _MsgPackGetFieldLayout(*MsgPackData.MsgPackData, *He
*ChildCount\q = ChildCount *ChildCount\q = ChildCount
Default: Default:
Debug("Invalid format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")") Debug("Invalid format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode *MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
ProcedureReturn #MsgPack_Error_InvalidFormatCode ProcedureReturn #MsgPack_Error_InvalidFormatCode
EndSelect EndSelect
@@ -341,7 +341,7 @@ Procedure.MsgPack_ErrorCode _MsgPackSkipFields(*MsgPackData.MsgPackData, FieldCo
EndIf EndIf
; Arrays and maps are at depth `Level + 1` from the structure's content. ; Arrays and maps are at depth `Level + 1` from the structure's content.
FormatByte = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) FormatByte = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)
If _MsgPackIsContainerFormatByte(FormatByte) And *MsgPackData\IteratorDepth + Level + 1 > #MsgPack_MaxDepth If _MsgPackIsContainerFormatByte(FormatByte) And *MsgPackData\IteratorDepth + Level + 1 > #MsgPack_MaxDepth
Debug("Arrays and maps are nested deeper than " + Str(#MsgPack_MaxDepth) + " levels !") Debug("Arrays and maps are nested deeper than " + Str(#MsgPack_MaxDepth) + " levels !")
*MsgPackData\LastError = #MsgPack_Error_MaxDepthExceeded *MsgPackData\LastError = #MsgPack_Error_MaxDepthExceeded
@@ -424,7 +424,7 @@ Procedure.q MsgPackGetEntryCount(*MsgPackData.MsgPackData)
ProcedureReturn ChildCount / 2 ProcedureReturn ChildCount / 2
EndSelect EndSelect
Debug("Unexpected format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")") Debug("Unexpected format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode *MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
ProcedureReturn #MsgPack_InvalidSize ProcedureReturn #MsgPack_InvalidSize
EndProcedure EndProcedure
@@ -486,7 +486,7 @@ Procedure.i MsgPackExamine(*MsgPackData.MsgPackData, ExaminationOptions.MsgPack_
DataType = MsgPackFormatCodeToDataType(MsgPackGetFormatCode(*MsgPackData)) DataType = MsgPackFormatCodeToDataType(MsgPackGetFormatCode(*MsgPackData))
If DataType <> #MsgPack_DataTypes_Array And DataType <> #MsgPack_DataTypes_Map If DataType <> #MsgPack_DataTypes_Array And DataType <> #MsgPack_DataTypes_Map
Debug("Attempted to examine format code 0x" + Debug("Attempted to examine format code 0x" +
RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") +
" as if it was an array or map !") " as if it was an array or map !")
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode *MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
ProcedureReturn #Null ProcedureReturn #Null
+4 -4
View File
@@ -72,13 +72,13 @@ Procedure.b MsgPackReadBoolean(*MsgPackData.MsgPackData)
; We don't check if we're 1 byte off the end since the previous check implies it. ; We don't check if we're 1 byte off the end since the previous check implies it.
If PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) = #MsgPack_FormatCode_False If FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) = #MsgPack_FormatCode_False
If _MsgPackHasFlag(*MsgPackData, #MsgPack_DataFlags_MoveOffsetAfterRead) If _MsgPackHasFlag(*MsgPackData, #MsgPack_DataFlags_MoveOffsetAfterRead)
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 *MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
EndIf EndIf
ProcedureReturn #False ProcedureReturn #False
ElseIf PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) = #MsgPack_FormatCode_True ElseIf FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) = #MsgPack_FormatCode_True
If _MsgPackHasFlag(*MsgPackData, #MsgPack_DataFlags_MoveOffsetAfterRead) If _MsgPackHasFlag(*MsgPackData, #MsgPack_DataFlags_MoveOffsetAfterRead)
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 *MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
EndIf EndIf
@@ -86,7 +86,7 @@ Procedure.b MsgPackReadBoolean(*MsgPackData.MsgPackData)
ProcedureReturn #True ProcedureReturn #True
Else Else
Debug("The format code isn't the one for a boolean ! (" + Debug("The format code isn't the one for a boolean ! (" +
RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") +
" vs "+ RSet(Hex(#MsgPack_FormatCode_False), 2, "0") + " vs "+ RSet(Hex(#MsgPack_FormatCode_False), 2, "0") +
"/"+ RSet(Hex(#MsgPack_FormatCode_True), 2, "0") + ")") "/"+ RSet(Hex(#MsgPack_FormatCode_True), 2, "0") + ")")
@@ -128,7 +128,7 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteLiteral(*MsgPackData.MsgPackData, Liter
EndIf EndIf
EndIf EndIf
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, LiteralFormatCode) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, LiteralFormatCode)
If _MsgPackHasFlag(*MsgPackData, #MsgPack_DataFlags_MoveOffsetAfterWrite) If _MsgPackHasFlag(*MsgPackData, #MsgPack_DataFlags_MoveOffsetAfterWrite)
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 *MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
+23 -23
View File
@@ -91,9 +91,9 @@ Procedure.MsgPack_ErrorCode _MsgPackExpectRead(*MsgPackData.MsgPackData, FormatC
ProcedureReturn #MsgPack_Error_AtOrPastTheEndOfBuffer ProcedureReturn #MsgPack_Error_AtOrPastTheEndOfBuffer
EndIf EndIf
If PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) <> FormatCode If FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) <> FormatCode
Debug("Unexpected format code ! (" + Debug("Unexpected format code ! (" +
RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") +
" vs "+ RSet(Hex(FormatCode), 2, "0") + ")") " vs "+ RSet(Hex(FormatCode), 2, "0") + ")")
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode *MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
ProcedureReturn #MsgPack_Error_InvalidFormatCode ProcedureReturn #MsgPack_Error_InvalidFormatCode
@@ -134,19 +134,19 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteFixedField(*MsgPackData.MsgPackData, Fo
Select ValueByteLength Select ValueByteLength
Case 0 Case 0
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode | (Value & $FF)) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode | (Value & $FF))
Case 1 Case 1
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, Value) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, Value)
Case 2 Case 2
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
PokeU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapU16(Value)) FastPokeU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapU16(Value))
Case 4 Case 4
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
PokeL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI32(Value)) FastPokeL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI32(Value))
Case 8 Case 8
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode) FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
PokeQ(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI64(Value)) FastPokeQ(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI64(Value))
EndSelect EndSelect
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 + ValueByteLength *MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 + ValueByteLength
_MsgPackRewindOffsetAfterWrite(*MsgPackData, 1 + ValueByteLength) _MsgPackRewindOffsetAfterWrite(*MsgPackData, 1 + ValueByteLength)
@@ -168,13 +168,13 @@ Procedure.q _MsgPackReadFixedField(*MsgPackData.MsgPackData, FormatCode.MsgPack_
Select ValueByteLength Select ValueByteLength
Case 1 Case 1
ReturnedValue = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1) ReturnedValue = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)
Case 2 Case 2
ReturnedValue = EndianSwapU16(PeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) ReturnedValue = EndianSwapU16(FastPeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
Case 4 Case 4
ReturnedValue = EndianSwapI32(PeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF ReturnedValue = EndianSwapI32(FastPeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF
Case 8 Case 8
ReturnedValue = EndianSwapI64(PeekQ(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) ReturnedValue = EndianSwapI64(FastPeekQ(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
EndSelect EndSelect
_MsgPackMoveOffsetAfterRead(*MsgPackData, 1 + ValueByteLength) _MsgPackMoveOffsetAfterRead(*MsgPackData, 1 + ValueByteLength)
@@ -359,7 +359,7 @@ Procedure.q MsgPackReadInteger(*MsgPackData.MsgPackData)
Case #MsgPack_FormatCode_FixIntPositive, Case #MsgPack_FormatCode_FixIntPositive,
#MsgPack_FormatCode_FixIntNegative: #MsgPack_FormatCode_FixIntNegative:
; The whole byte is the value, both ranges are valid signed bytes. ; The whole byte is the value, both ranges are valid signed bytes.
ReturnedValue = PeekB(*MsgPackData\Buffer + *MsgPackData\BufferOffset) ReturnedValue = FastPeekB(*MsgPackData\Buffer + *MsgPackData\BufferOffset)
_MsgPackMoveOffsetAfterRead(*MsgPackData, 1) _MsgPackMoveOffsetAfterRead(*MsgPackData, 1)
*MsgPackData\LastError = #MsgPack_Error_Success *MsgPackData\LastError = #MsgPack_Error_Success
ProcedureReturn ReturnedValue ProcedureReturn ReturnedValue
@@ -370,7 +370,7 @@ Procedure.q MsgPackReadInteger(*MsgPackData.MsgPackData)
Case #MsgPack_FormatCode_UInt32: Case #MsgPack_FormatCode_UInt32:
ProcedureReturn _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_UInt32, 4) ProcedureReturn _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_UInt32, 4)
Case #MsgPack_FormatCode_UInt64: Case #MsgPack_FormatCode_UInt64:
If _MsgPackHasSpaceLeft(*MsgPackData, 9) And (PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1) & $80) If _MsgPackHasSpaceLeft(*MsgPackData, 9) And (FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1) & $80)
Debug("UInt64 value doesn't fit in a signed quad !") Debug("UInt64 value doesn't fit in a signed quad !")
*MsgPackData\LastError = #MsgPack_Error_ValueOverflow *MsgPackData\LastError = #MsgPack_Error_ValueOverflow
ProcedureReturn 0 ProcedureReturn 0
@@ -386,7 +386,7 @@ Procedure.q MsgPackReadInteger(*MsgPackData.MsgPackData)
ProcedureReturn MsgPackReadInt64(*MsgPackData) ProcedureReturn MsgPackReadInt64(*MsgPackData)
EndSelect EndSelect
Debug("Unexpected format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")") Debug("Unexpected format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode *MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
ProcedureReturn 0 ProcedureReturn 0
EndProcedure EndProcedure
@@ -397,14 +397,14 @@ EndProcedure
; The value's bits are moved and swapped as an integer, since loading a byte-swapped ; The value's bits are moved and swapped as an integer, since loading a byte-swapped
; float into the FPU can alter its bits. (e.g.: NaN quieting on x87) ; float into the FPU can alter its bits. (e.g.: NaN quieting on x87)
Procedure.MsgPack_ErrorCode MsgPackWriteFloat32(*MsgPackData.MsgPackData, Value.f) Procedure.MsgPack_ErrorCode MsgPackWriteFloat32(*MsgPackData.MsgPackData, Value.f)
ProcedureReturn _MsgPackWriteFixedField(*MsgPackData, #MsgPack_FormatCode_Float32, 4, PeekL(@Value)) ProcedureReturn _MsgPackWriteFixedField(*MsgPackData, #MsgPack_FormatCode_Float32, 4, FastPeekL(@Value))
EndProcedure EndProcedure
Procedure.f MsgPackReadFloat32(*MsgPackData.MsgPackData) Procedure.f MsgPackReadFloat32(*MsgPackData.MsgPackData)
Protected ReturnedValue.f Protected ReturnedValue.f
PokeL(@ReturnedValue, _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_Float32, 4)) FastPokeL(@ReturnedValue, _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_Float32, 4))
ProcedureReturn ReturnedValue ProcedureReturn ReturnedValue
EndProcedure EndProcedure
@@ -415,14 +415,14 @@ EndProcedure
; The value's bits are moved and swapped as an integer, since loading a byte-swapped ; The value's bits are moved and swapped as an integer, since loading a byte-swapped
; float into the FPU can alter its bits. (e.g.: NaN quieting on x87) ; float into the FPU can alter its bits. (e.g.: NaN quieting on x87)
Procedure.MsgPack_ErrorCode MsgPackWriteFloat64(*MsgPackData.MsgPackData, Value.d) Procedure.MsgPack_ErrorCode MsgPackWriteFloat64(*MsgPackData.MsgPackData, Value.d)
ProcedureReturn _MsgPackWriteFixedField(*MsgPackData, #MsgPack_FormatCode_Float64, 8, PeekQ(@Value)) ProcedureReturn _MsgPackWriteFixedField(*MsgPackData, #MsgPack_FormatCode_Float64, 8, FastPeekQ(@Value))
EndProcedure EndProcedure
Procedure.d MsgPackReadFloat64(*MsgPackData.MsgPackData) Procedure.d MsgPackReadFloat64(*MsgPackData.MsgPackData)
Protected ReturnedValue.d Protected ReturnedValue.d
PokeQ(@ReturnedValue, _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_Float64, 8)) FastPokeQ(@ReturnedValue, _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_Float64, 8))
ProcedureReturn ReturnedValue ProcedureReturn ReturnedValue
EndProcedure EndProcedure
@@ -454,7 +454,7 @@ Procedure.d MsgPackReadFloat(*MsgPackData.MsgPackData)
ProcedureReturn MsgPackReadFloat64(*MsgPackData) ProcedureReturn MsgPackReadFloat64(*MsgPackData)
EndSelect EndSelect
Debug("Unexpected format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")") Debug("Unexpected format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode *MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
ProcedureReturn 0 ProcedureReturn 0
EndProcedure EndProcedure
+1 -1
View File
@@ -46,7 +46,7 @@ Procedure.MsgPack_FormatCode MsgPackGetFormatCode(*MsgPackData.MsgPackData)
ProcedureReturn #MsgPack_FormatCode_Invalid ProcedureReturn #MsgPack_FormatCode_Invalid
EndIf EndIf
DataFormatCode = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) DataFormatCode = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)
If DataFormatCode < $80 If DataFormatCode < $80
; 0x00 - 0x7F ; 0x00 - 0x7F