OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2015 Google Inc. All rights reserved. | 2 * Copyright (C) 2015 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 FastSharedBufferReader(PassRefPtr<SharedBuffer> data); | 47 FastSharedBufferReader(PassRefPtr<SharedBuffer> data); |
48 | 48 |
49 void setData(PassRefPtr<SharedBuffer>); | 49 void setData(PassRefPtr<SharedBuffer>); |
50 | 50 |
51 // Returns a consecutive buffer that carries the data starting | 51 // Returns a consecutive buffer that carries the data starting |
52 // at |dataPosition| with |length| bytes. | 52 // at |dataPosition| with |length| bytes. |
53 // This method returns a pointer to a memory segment stored in | 53 // This method returns a pointer to a memory segment stored in |
54 // |m_data| if such a consecutive buffer can be found. | 54 // |m_data| if such a consecutive buffer can be found. |
55 // Otherwise copies into |buffer| and returns it. | 55 // Otherwise copies into |buffer| and returns it. |
56 // Caller must ensure there are enough bytes in |m_data| and |buffer|. | 56 // Caller must ensure there are enough bytes in |m_data| and |buffer|. |
57 const char* getConsecutiveData(size_t dataPosition, size_t length, char* buf
fer); | 57 const char* getConsecutiveData(size_t dataPosition, size_t length, char* buf
fer) const; |
58 | 58 |
59 // Wraps SharedBuffer::getSomeData(). | 59 // Wraps SharedBuffer::getSomeData(). |
60 size_t getSomeData(const char*& someData, size_t dataPosition); | 60 size_t getSomeData(const char*& someData, size_t dataPosition) const; |
61 | 61 |
62 // Returns a byte at |dataPosition|. | 62 // Returns a byte at |dataPosition|. |
63 // Caller must ensure there are enough bytes in |m_data|. | 63 // Caller must ensure there are enough bytes in |m_data|. |
64 inline char getOneByte(size_t dataPosition) | 64 inline char getOneByte(size_t dataPosition) const |
65 { | 65 { |
66 return *getConsecutiveData(dataPosition, 1, 0); | 66 return *getConsecutiveData(dataPosition, 1, 0); |
67 } | 67 } |
68 | 68 |
69 size_t size() const | 69 size_t size() const |
70 { | 70 { |
71 return m_data->size(); | 71 return m_data->size(); |
72 } | 72 } |
73 | 73 |
74 private: | 74 private: |
75 void getSomeDataInternal(unsigned dataPosition); | 75 void getSomeDataInternal(unsigned dataPosition) const; |
76 | 76 |
77 RefPtr<SharedBuffer> m_data; | 77 RefPtr<SharedBuffer> m_data; |
78 | 78 |
79 // Caches the last segment of |m_data| accessed, since subsequent reads are | 79 // Caches the last segment of |m_data| accessed, since subsequent reads are |
80 // likely to re-access it. | 80 // likely to re-access it. |
81 const char* m_segment; | 81 mutable const char* m_segment; |
82 size_t m_segmentLength; | 82 mutable size_t m_segmentLength; |
83 | 83 |
84 // Data position in |m_data| pointed to by |m_segment|. | 84 // Data position in |m_data| pointed to by |m_segment|. |
85 size_t m_dataPosition; | 85 mutable size_t m_dataPosition; |
86 }; | 86 }; |
87 | 87 |
88 } // namespace blink | 88 } // namespace blink |
89 | 89 |
90 #endif | 90 #endif |
OLD | NEW |