예제 #1
0
ByteArray &ByteArray::insertConstant(size_t index, BYTE b, size_t count) {
  if(count == 0) {
    return *this;
  }
  if(index > m_size) {
    indexError(__TFUNCTION__, index);
  }
  const size_t newSize = m_size + count;
  if(newSize > m_capacity) {
    const size_t newCapacity = getCapacityCeil(2 * newSize);
    BYTE *newData = allocateBytes(newCapacity);
    if(index > 0) {
      memcpy(newData, m_data, index);
    }
    if(index < m_size) {
      memcpy(newData+index+count, m_data+index, m_size-index);
    }
    if(m_data != NULL) {
      deallocateBytes(m_data);
    }
    m_data = newData;
    m_capacity = newCapacity;
  } else if(index < m_size) {
    memmove(m_data+index+count, m_data+index, m_size-index);
  }
  memset(m_data+index, b, count);
  m_size = newSize;
  return *this;
}
예제 #2
0
파일: space.cpp 프로젝트: AdamSpitz/klein
oop Space::clone( oop original ) {
  oop mapOop = MemoryObjectLayout().mapOf(original);
  int oldBytesBottom = bytesBottom;
  int oldOopsTop     = oopsTop;
  allocateOops (oriMap -> oopSize);
  allocateBytes(oriMap -> byteSize);
  copyOopPart  (oriMap -> oopPart()  , oldOopsTop    , oopsTop    );
  copyBytesPart(oriMap -> bytesPart(), oldBytesBottom, bytesBottom);
  Map* newMap = mapForOop(oldOopsTop);
  newMap -> adjustForNewOop       (oldOopsTop);
  newMap -> adjustForNewBytesPart (oldBytesBottom);
  return oldOopsTop;
}
예제 #3
0
void ByteArray::setCapacity(size_t capacity) {
  if(capacity < m_size) {
    capacity = m_size;
  }
  capacity = getCapacityCeil(capacity);
  if(capacity == 0) {
    cleanup();
  } else if(capacity != m_capacity) {
    BYTE *newData = allocateBytes(capacity);
    if(m_size > 0) {
      memcpy(newData, m_data, m_size);
      deallocateBytes(m_data);
    }
    m_data     = newData;
    m_capacity = capacity;
  }
}
예제 #4
0
ByteArray &ByteArray::append(const BYTE *data, size_t size) {
  if(size) {
    const size_t newSize = m_size + size;
    if(newSize > m_capacity) {     // Careful here!!! data and m_data might overlap!!
      const size_t newCapacity = getCapacityCeil(2 * newSize); // > 0
      BYTE *newData = allocateBytes(newCapacity);
      if(m_size > 0) {
        memcpy(newData, m_data, m_size);
      }
      memcpy(newData + m_size, data, size);
      if(m_data != NULL) { // Now we can safely delete m_data.
        deallocateBytes(m_data);
      }
      m_data     = newData;
      m_capacity = newCapacity;
    } else {
      memcpy(m_data+m_size, data, size);
    }
    m_size = newSize;
  }
  return *this;
}
예제 #5
0
파일: arena.cpp 프로젝트: QingYun/kj
StringPtr Arena::copyString(StringPtr content) {
  char* data = reinterpret_cast<char*>(allocateBytes(content.size() + 1, 1, false));
  memcpy(data, content.cStr(), content.size() + 1);
  return StringPtr(data, content.size());
}