File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -10,13 +10,17 @@ import ../Utils/addr0
1010# XXX: Nim's string ops has bugs for NUL('\0') char, e.g. len('1\02') gives 2
1111declarePyType Bytes (tpToken):
1212 items: seq [char ]
13- setHash: bool
14- privateHash: Hash
13+ setHash{. private .} : bool
14+ privateHash{. private .} : Hash
1515
1616declarePyType ByteArray (reprLock, mutable):
1717 items: seq [char ]
1818
19- proc hash * (self: PyBytesObject ): Hash = Py_HashBuffer (self.items)
19+ proc hash * (self: PyBytesObject ): Hash =
20+ if self.setHash: return self.privateHash
21+ self.setHash = true
22+ result = Py_HashBuffer (self.items)
23+ self.privateHash = result
2024
2125type PyBytesWriter * = object
2226 # overallocate*: bool
@@ -46,6 +50,8 @@ proc `$`(self: seq[char]): string =
4650
4751type PyByteLike = PyBytesObject or PyByteArrayObject
4852
53+ proc `==` * (a, b: PyBytesObject ): bool {. inline .} = a.hash == b.hash and a.items == b.items
54+ proc `==` * (a, b: PyByteArrayObject ): bool {. inline .} = a.items == b.items
4955proc len * (s: PyByteLike ): int {. inline , cdecl .} = s.items.len
5056proc `$` * (s: PyByteLike ): string = $ s.items
5157iterator items * (s: PyByteLike ): char =
You can’t perform that action at this time.
0 commit comments