2121namespace paimon {
2222std::shared_ptr<MemorySlice> MemorySlice::Wrap (const std::shared_ptr<Bytes>& bytes) {
2323 auto segment = MemorySegment::Wrap (bytes);
24- auto ptr = std::make_shared<MemorySegment>(segment);
25- return std::make_shared<MemorySlice>(ptr, 0 , ptr->Size ());
24+ return std::make_shared<MemorySlice>(segment, 0 , segment.Size ());
2625}
2726
28- std::shared_ptr<MemorySlice> MemorySlice::Wrap (const std::shared_ptr< MemorySegment> & segment) {
29- return std::make_shared<MemorySlice>(segment, 0 , segment-> Size ());
27+ std::shared_ptr<MemorySlice> MemorySlice::Wrap (const MemorySegment& segment) {
28+ return std::make_shared<MemorySlice>(segment, 0 , segment. Size ());
3029}
3130
32- MemorySlice::MemorySlice (const std::shared_ptr<MemorySegment>& segment, int32_t offset,
33- int32_t length)
31+ MemorySlice::MemorySlice (const MemorySegment& segment, int32_t offset, int32_t length)
3432 : segment_(segment), offset_(offset), length_(length) {}
3533
3634std::shared_ptr<MemorySlice> MemorySlice::Slice (int32_t index, int32_t length) {
@@ -49,38 +47,38 @@ int32_t MemorySlice::Offset() const {
4947}
5048
5149std::shared_ptr<Bytes> MemorySlice::GetHeapMemory () const {
52- return segment_-> GetHeapMemory ();
50+ return segment_. GetHeapMemory ();
5351}
5452
55- std::shared_ptr< MemorySegment> MemorySlice::GetSegment () const {
53+ const MemorySegment& MemorySlice::GetSegment () const {
5654 return segment_;
5755}
5856
5957int8_t MemorySlice::ReadByte (int32_t position) {
60- return segment_-> GetValue <int8_t >(offset_ + position);
58+ return segment_. GetValue <int8_t >(offset_ + position);
6159}
6260
6361int32_t MemorySlice::ReadInt (int32_t position) {
64- return segment_-> GetValue <int32_t >(offset_ + position);
62+ return segment_. GetValue <int32_t >(offset_ + position);
6563}
6664
6765int16_t MemorySlice::ReadShort (int32_t position) {
68- return segment_-> GetValue <int16_t >(offset_ + position);
66+ return segment_. GetValue <int16_t >(offset_ + position);
6967}
7068
7169int64_t MemorySlice::ReadLong (int32_t position) {
72- return segment_-> GetValue <int64_t >(offset_ + position);
70+ return segment_. GetValue <int64_t >(offset_ + position);
7371}
7472
7573std::string_view MemorySlice::ReadStringView () {
76- auto array = segment_-> GetArray ();
74+ auto array = segment_. GetArray ();
7775 return {array->data () + offset_, static_cast <size_t >(length_)};
7876}
7977
8078std::shared_ptr<Bytes> MemorySlice::CopyBytes (MemoryPool* pool) {
8179 auto bytes = std::make_shared<Bytes>(length_, pool);
8280 auto target = MemorySegment::Wrap (bytes);
83- segment_-> CopyTo (offset_, &target, 0 , length_);
81+ segment_. CopyTo (offset_, &target, 0 , length_);
8482 return bytes;
8583}
8684
@@ -110,8 +108,8 @@ std::shared_ptr<MemorySliceInput> MemorySlice::ToInput() {
110108int32_t MemorySlice::Compare (const MemorySlice& other) const {
111109 int32_t len = std::min (length_, other.length_ );
112110 for (int32_t i = 0 ; i < len; ++i) {
113- auto byte1 = static_cast <unsigned char >(segment_-> Get (offset_ + i));
114- auto byte2 = static_cast <unsigned char >(other.segment_ -> Get (other.offset_ + i));
111+ auto byte1 = static_cast <unsigned char >(segment_. Get (offset_ + i));
112+ auto byte2 = static_cast <unsigned char >(other.segment_ . Get (other.offset_ + i));
115113 if (byte1 != byte2) {
116114 return static_cast <int >(byte1) - static_cast <int >(byte2);
117115 }
0 commit comments