~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/vm/SectionReader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <SectionReader.hpp>
 
17
#include <TransporterDefinitions.hpp>
 
18
#include "LongSignal.hpp"
 
19
 
 
20
#if 0
 
21
  Uint32 m_len;
 
22
  class SectionSegmentPool & m_pool;
 
23
  class SectionSegment * m_head;
 
24
  class SectionSegment * m_currentPos;
 
25
#endif
 
26
 
 
27
SectionReader::SectionReader
 
28
(struct SegmentedSectionPtr & ptr, class SectionSegmentPool & pool)
 
29
  : m_pool(pool)
 
30
{
 
31
  if(ptr.p == 0){
 
32
    m_pos = 0;
 
33
    m_len = 0;
 
34
    m_head = 0;
 
35
    m_currentSegment = 0;
 
36
  } else {
 
37
    m_pos = 0;
 
38
    m_len = ptr.p->m_sz;
 
39
    m_head = ptr.p;
 
40
    m_currentSegment = ptr.p;
 
41
  }
 
42
}
 
43
 
 
44
void
 
45
SectionReader::reset(){
 
46
  m_pos = 0;
 
47
  m_currentSegment = m_head;
 
48
}
 
49
 
 
50
bool
 
51
SectionReader::step(Uint32 len){
 
52
  if(m_pos + len >= m_len) {
 
53
    m_pos++;
 
54
    return false;
 
55
  }
 
56
  while(len > SectionSegment::DataLength){
 
57
    m_currentSegment = m_pool.getPtr(m_currentSegment->m_nextSegment);
 
58
 
 
59
    len -= SectionSegment::DataLength;
 
60
    m_pos += SectionSegment::DataLength;
 
61
  }
 
62
 
 
63
  Uint32 ind = m_pos % SectionSegment::DataLength;
 
64
  while(len > 0){
 
65
    len--;
 
66
    m_pos++;
 
67
 
 
68
    ind++;
 
69
    if(ind == SectionSegment::DataLength){
 
70
      ind = 0;
 
71
      m_currentSegment = m_pool.getPtr(m_currentSegment->m_nextSegment);
 
72
    }
 
73
  }
 
74
  return true;
 
75
}
 
76
 
 
77
bool
 
78
SectionReader::getWord(Uint32 * dst){
 
79
  if (peekWord(dst)) {
 
80
    step(1);
 
81
    return true;
 
82
  }
 
83
  return false;
 
84
}
 
85
 
 
86
bool
 
87
SectionReader::peekWord(Uint32 * dst) const {
 
88
  if(m_pos < m_len){
 
89
    Uint32 ind = m_pos % SectionSegment::DataLength;
 
90
    * dst = m_currentSegment->theData[ind];
 
91
    return true;
 
92
  }
 
93
  return false;
 
94
}
 
95
 
 
96
bool
 
97
SectionReader::peekWords(Uint32 * dst, Uint32 len) const {
 
98
  if(m_pos + len > m_len)
 
99
    return false;
 
100
 
 
101
  Uint32 ind = (m_pos % SectionSegment::DataLength);
 
102
  Uint32 left = SectionSegment::DataLength - ind;
 
103
  SectionSegment * p = m_currentSegment;
 
104
 
 
105
  while(len > left){
 
106
    memcpy(dst, &p->theData[ind], 4 * left);
 
107
    dst += left;
 
108
    len -= left;
 
109
    ind = 0;
 
110
    left = SectionSegment::DataLength;
 
111
    p = m_pool.getPtr(p->m_nextSegment);
 
112
  }
 
113
 
 
114
  memcpy(dst, &p->theData[ind], 4 * len);
 
115
  return true;
 
116
}
 
117
 
 
118
bool
 
119
SectionReader::getWords(Uint32 * dst, Uint32 len){
 
120
  if(m_pos + len > m_len)
 
121
    return false;
 
122
 
 
123
  Uint32 ind = (m_pos % SectionSegment::DataLength);
 
124
  Uint32 left = SectionSegment::DataLength - ind;
 
125
  SectionSegment * p = m_currentSegment;
 
126
 
 
127
  while(len > left){
 
128
    memcpy(dst, &p->theData[ind], 4 * left);
 
129
    dst += left;
 
130
    len -= left;
 
131
    ind = 0;
 
132
    left = SectionSegment::DataLength;
 
133
    p = m_pool.getPtr(p->m_nextSegment);
 
134
  }
 
135
 
 
136
  memcpy(dst, &p->theData[ind], 4 * len);
 
137
 
 
138
  m_pos += len;
 
139
  m_currentSegment = p;
 
140
  return true;
 
141
}
 
142