@@ -85,7 +85,6 @@ proc newStructContext(): StructContext =
85
85
result .index = 0
86
86
87
87
proc `$` * ( node: StructNode ): string =
88
- # # Delegate stringification of `TNetstringNode` to its underlying object.
89
88
return case node.kind:
90
89
of StructChar :
91
90
$ node.ch
@@ -98,49 +97,38 @@ proc `$`*( node: StructNode ): string =
98
97
of StructString :
99
98
$ node.str
100
99
101
- proc getChar * (node: StructNode ): char {.noSideEffect , procVar .} =
102
- assert node.kind == StructChar
103
- result = node.ch
100
+ proc getChar * (node: StructNode ): char {.noSideEffect , inline .} =
101
+ node.ch
104
102
105
- proc getBool * (node: StructNode ): bool {.noSideEffect , procVar .} =
106
- assert node.kind == StructBool
107
- result = node.bval
103
+ proc getBool * (node: StructNode ): bool {.noSideEffect , inline .} =
104
+ node.bval
108
105
109
- proc getShort * (node: StructNode ): int16 {.noSideEffect , procVar .} =
110
- assert node.kind == StructInt
111
- result = node.num.int16
106
+ proc getShort * (node: StructNode ): int16 {.noSideEffect , inline .} =
107
+ node.num.int16
112
108
113
- proc getUShort * (node: StructNode ): uint16 {.noSideEffect , procVar .} =
114
- assert node.kind == StructInt
115
- result = node.num.uint16
109
+ proc getUShort * (node: StructNode ): uint16 {.noSideEffect , inline .} =
110
+ node.num.uint16
116
111
117
- proc getInt * (node: StructNode ): int32 {.noSideEffect , procVar .} =
118
- assert node.kind == StructInt
119
- result = node.num.int32
112
+ proc getInt * (node: StructNode ): int32 {.noSideEffect , inline .} =
113
+ node.num.int32
120
114
121
- proc getUInt * (node: StructNode ): uint32 {.noSideEffect , procVar .} =
122
- assert node.kind == StructInt
123
- result = node.num.uint16
115
+ proc getUInt * (node: StructNode ): uint32 {.noSideEffect , inline .} =
116
+ node.num.uint16
124
117
125
- proc getQuad * (node: StructNode ): int64 {.noSideEffect , procVar .} =
126
- assert node.kind == StructInt
127
- result = node.num.int64
118
+ proc getQuad * (node: StructNode ): int64 {.noSideEffect , inline .} =
119
+ node.num.int64
128
120
129
- proc getUQuad * (node: StructNode ): uint64 {.noSideEffect , procVar .} =
130
- assert node.kind == StructInt
131
- result = node.num.uint64
121
+ proc getUQuad * (node: StructNode ): uint64 {.noSideEffect , inline .} =
122
+ node.num.uint64
132
123
133
- proc getFloat * (node: StructNode ): float32 {.noSideEffect , procVar .} =
134
- assert node.kind == StructFloat
135
- result = node.fval.float32
124
+ proc getFloat * (node: StructNode ): float32 {.noSideEffect , inline .} =
125
+ node.fval.float32
136
126
137
- proc getDouble * (node: StructNode ): float64 {.noSideEffect , procVar .} =
138
- assert node.kind == StructFloat
139
- result = node.fval.float64
127
+ proc getDouble * (node: StructNode ): float64 {.noSideEffect , inline .} =
128
+ node.fval.float64
140
129
141
- proc getString * (node: StructNode ): string {.noSideEffect , procVar .} =
142
- assert node.kind == StructString
143
- return node.str
130
+ proc getString * (node: StructNode ): string {.noSideEffect , inline .} =
131
+ node.str
144
132
145
133
proc calcsize (format: string ): int =
146
134
var repeat = newString (0 )
@@ -275,7 +263,7 @@ proc unpack_string(vars: var seq[StructNode], ctx: var StructContext) =
275
263
else :
276
264
value = ctx.buffer[ctx.offset.. ctx.offset+ ctx.repeat- 1 ]
277
265
vars.add (newStructString (value))
278
- ctx.offset += ctx.repeat
266
+ inc ( ctx.offset, ctx.repeat)
279
267
280
268
281
269
@@ -329,7 +317,7 @@ proc unpack*(fmt, buf: string): seq[StructNode] =
329
317
of 's' :
330
318
unpack_string (result , context)
331
319
of 'x' :
332
- context.offset += context.repeat * getSize (f)
320
+ inc ( context.offset, context.repeat * getSize (f) )
333
321
else :
334
322
raise newException (ValueError , " bad char in struct format" )
335
323
0 commit comments