mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
f0a2ea215e
commit
c0e06c3144
@ -61,11 +61,12 @@ struct Bytes{
|
||||
return _data != rhs._data;
|
||||
}
|
||||
|
||||
std::string str() const noexcept { return std::string(_data.begin(), _data.end()); }
|
||||
Str str() const noexcept { return Str(_data.data(), _data.size()); }
|
||||
|
||||
Bytes() : _data(), _ok(false) {}
|
||||
Bytes(std::vector<char>&& data) : _data(std::move(data)), _ok(true) {}
|
||||
Bytes(const std::string& data) : _data(data.begin(), data.end()), _ok(true) {}
|
||||
Bytes(const Str& data) : _data(data.begin(), data.end()), _ok(true) {}
|
||||
Bytes(std::string_view sv): _data(sv.begin(), sv.end()), _ok(true) {}
|
||||
operator bool() const noexcept { return _ok; }
|
||||
};
|
||||
|
||||
|
Binary file not shown.
@ -916,7 +916,8 @@ void init_builtins(VM* _vm) {
|
||||
|
||||
_vm->bind__hash__(_vm->tp_bytes, [](VM* vm, PyObject* obj) {
|
||||
const Bytes& self = _CAST(Bytes&, obj);
|
||||
return (i64)std::hash<std::string>()(self.str());
|
||||
std::string_view view(self.data(), self.size());
|
||||
return (i64)std::hash<std::string_view>()(view);
|
||||
});
|
||||
|
||||
_vm->bind__repr__(_vm->tp_bytes, [](VM* vm, PyObject* obj) {
|
||||
|
@ -3,3 +3,6 @@ assert a.encode() == b'12345'
|
||||
|
||||
assert b'\xff\xee' != b'1234'
|
||||
assert b'\xff\xee' == b'\xff\xee'
|
||||
|
||||
a = '测试123'
|
||||
assert a == a.encode().decode()
|
Loading…
x
Reference in New Issue
Block a user