mirror of
https://github.com/MariaDB/server.git
synced 2025-01-24 07:44:22 +01:00
cee82bca29
into dl145b.mysql.com:/home/ndbdev/tomas/mysql-5.1 sql/ha_innodb.cc: Auto merged sql/ha_innodb.h: Auto merged sql/mysqld.cc: Auto merged storage/innobase/btr/btr0btr.c: Auto merged storage/innobase/btr/btr0cur.c: Auto merged storage/innobase/btr/btr0pcur.c: Auto merged storage/innobase/btr/btr0sea.c: Auto merged storage/innobase/buf/buf0buf.c: Auto merged storage/innobase/buf/buf0flu.c: Auto merged storage/innobase/buf/buf0lru.c: Auto merged storage/innobase/buf/buf0rea.c: Auto merged storage/innobase/data/data0data.c: Auto merged storage/innobase/data/data0type.c: Auto merged storage/innobase/dict/dict0boot.c: Auto merged storage/innobase/dict/dict0crea.c: Auto merged storage/innobase/dict/dict0dict.c: Auto merged storage/innobase/dict/dict0mem.c: Auto merged storage/innobase/fil/fil0fil.c: Auto merged storage/innobase/fsp/fsp0fsp.c: Auto merged storage/innobase/ibuf/ibuf0ibuf.c: Auto merged storage/innobase/include/btr0btr.h: Auto merged storage/innobase/include/btr0btr.ic: Auto merged storage/innobase/include/btr0cur.h: Auto merged storage/innobase/include/btr0cur.ic: Auto merged storage/innobase/include/buf0buf.h: Auto merged storage/innobase/include/buf0buf.ic: Auto merged storage/innobase/include/buf0lru.h: Auto merged storage/innobase/include/data0type.h: Auto merged storage/innobase/include/data0type.ic: Auto merged storage/innobase/include/dyn0dyn.h: Auto merged storage/innobase/include/dyn0dyn.ic: Auto merged storage/innobase/include/lock0lock.h: Auto merged storage/innobase/include/log0log.h: Auto merged storage/innobase/include/mach0data.h: Auto merged storage/innobase/include/mach0data.ic: Auto merged storage/innobase/include/mem0mem.ic: Auto merged storage/innobase/include/mtr0log.h: Auto merged storage/innobase/include/mtr0mtr.h: Auto merged storage/innobase/include/os0file.h: Auto merged storage/innobase/include/page0cur.h: Auto merged storage/innobase/include/page0cur.ic: Auto merged storage/innobase/include/page0page.h: Auto merged storage/innobase/include/page0page.ic: Auto merged storage/innobase/include/read0read.ic: Auto merged storage/innobase/include/rem0rec.h: Auto merged storage/innobase/include/rem0rec.ic: Auto merged storage/innobase/include/row0mysql.h: Auto merged storage/innobase/include/row0sel.ic: Auto merged storage/innobase/include/row0upd.ic: Auto merged storage/innobase/include/sync0rw.ic: Auto merged storage/innobase/include/trx0rseg.ic: Auto merged storage/innobase/include/trx0trx.h: Auto merged storage/innobase/include/univ.i: Auto merged storage/innobase/include/ut0dbg.h: Auto merged storage/innobase/include/ut0rnd.ic: Auto merged storage/innobase/lock/lock0lock.c: Auto merged storage/innobase/log/log0log.c: Auto merged storage/innobase/log/log0recv.c: Auto merged storage/innobase/mtr/mtr0log.c: Auto merged storage/innobase/mtr/mtr0mtr.c: Auto merged storage/innobase/os/os0file.c: Auto merged storage/innobase/page/page0cur.c: Auto merged storage/innobase/page/page0page.c: Auto merged storage/innobase/rem/rem0cmp.c: Auto merged storage/innobase/rem/rem0rec.c: Auto merged storage/innobase/row/row0ins.c: Auto merged storage/innobase/row/row0mysql.c: Auto merged storage/innobase/row/row0purge.c: Auto merged storage/innobase/row/row0row.c: Auto merged storage/innobase/row/row0sel.c: Auto merged storage/innobase/row/row0undo.c: Auto merged storage/innobase/row/row0upd.c: Auto merged storage/innobase/row/row0vers.c: Auto merged storage/innobase/srv/srv0start.c: Auto merged storage/innobase/sync/sync0sync.c: Auto merged storage/innobase/trx/trx0rec.c: Auto merged storage/innobase/trx/trx0roll.c: Auto merged storage/innobase/trx/trx0trx.c: Auto merged storage/innobase/ut/ut0dbg.c: Auto merged
344 lines
7.3 KiB
Text
344 lines
7.3 KiB
Text
/******************************************************
|
|
The dynamically allocated array
|
|
|
|
(c) 1996 Innobase Oy
|
|
|
|
Created 2/5/1996 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#define DYN_BLOCK_MAGIC_N 375767
|
|
#define DYN_BLOCK_FULL_FLAG 0x1000000UL
|
|
|
|
/****************************************************************
|
|
Adds a new block to a dyn array. */
|
|
|
|
dyn_block_t*
|
|
dyn_array_add_block(
|
|
/*================*/
|
|
/* out: created block */
|
|
dyn_array_t* arr); /* in: dyn array */
|
|
|
|
|
|
/****************************************************************
|
|
Gets the first block in a dyn array. */
|
|
UNIV_INLINE
|
|
dyn_block_t*
|
|
dyn_array_get_first_block(
|
|
/*======================*/
|
|
dyn_array_t* arr) /* in: dyn array */
|
|
{
|
|
return(arr);
|
|
}
|
|
|
|
/****************************************************************
|
|
Gets the last block in a dyn array. */
|
|
UNIV_INLINE
|
|
dyn_block_t*
|
|
dyn_array_get_last_block(
|
|
/*=====================*/
|
|
dyn_array_t* arr) /* in: dyn array */
|
|
{
|
|
if (arr->heap == NULL) {
|
|
|
|
return(arr);
|
|
}
|
|
|
|
return(UT_LIST_GET_LAST(arr->base));
|
|
}
|
|
|
|
/************************************************************************
|
|
Gets the next block in a dyn array. */
|
|
UNIV_INLINE
|
|
dyn_block_t*
|
|
dyn_array_get_next_block(
|
|
/*=====================*/
|
|
/* out: pointer to next, NULL if end of list */
|
|
dyn_array_t* arr, /* in: dyn array */
|
|
dyn_block_t* block) /* in: dyn array block */
|
|
{
|
|
ut_ad(arr && block);
|
|
|
|
if (arr->heap == NULL) {
|
|
ut_ad(arr == block);
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
return(UT_LIST_GET_NEXT(list, block));
|
|
}
|
|
|
|
/************************************************************************
|
|
Gets the number of used bytes in a dyn array block. */
|
|
UNIV_INLINE
|
|
ulint
|
|
dyn_block_get_used(
|
|
/*===============*/
|
|
/* out: number of bytes used */
|
|
dyn_block_t* block) /* in: dyn array block */
|
|
{
|
|
ut_ad(block);
|
|
|
|
return((block->used) & ~DYN_BLOCK_FULL_FLAG);
|
|
}
|
|
|
|
/************************************************************************
|
|
Gets pointer to the start of data in a dyn array block. */
|
|
UNIV_INLINE
|
|
byte*
|
|
dyn_block_get_data(
|
|
/*===============*/
|
|
/* out: pointer to data */
|
|
dyn_block_t* block) /* in: dyn array block */
|
|
{
|
|
ut_ad(block);
|
|
|
|
return(block->data);
|
|
}
|
|
|
|
/*************************************************************************
|
|
Initializes a dynamic array. */
|
|
UNIV_INLINE
|
|
dyn_array_t*
|
|
dyn_array_create(
|
|
/*=============*/
|
|
/* out: initialized dyn array */
|
|
dyn_array_t* arr) /* in: pointer to a memory buffer of
|
|
size sizeof(dyn_array_t) */
|
|
{
|
|
ut_ad(arr);
|
|
ut_ad(DYN_ARRAY_DATA_SIZE < DYN_BLOCK_FULL_FLAG);
|
|
|
|
arr->heap = NULL;
|
|
arr->used = 0;
|
|
|
|
#ifdef UNIV_DEBUG
|
|
arr->buf_end = 0;
|
|
arr->magic_n = DYN_BLOCK_MAGIC_N;
|
|
#endif
|
|
return(arr);
|
|
}
|
|
|
|
/****************************************************************
|
|
Frees a dynamic array. */
|
|
UNIV_INLINE
|
|
void
|
|
dyn_array_free(
|
|
/*===========*/
|
|
dyn_array_t* arr) /* in: dyn array */
|
|
{
|
|
if (arr->heap != NULL) {
|
|
mem_heap_free(arr->heap);
|
|
}
|
|
|
|
#ifdef UNIV_DEBUG
|
|
arr->magic_n = 0;
|
|
#endif
|
|
}
|
|
|
|
/*************************************************************************
|
|
Makes room on top of a dyn array and returns a pointer to the added element.
|
|
The caller must copy the element to the pointer returned. */
|
|
UNIV_INLINE
|
|
void*
|
|
dyn_array_push(
|
|
/*===========*/
|
|
/* out: pointer to the element */
|
|
dyn_array_t* arr, /* in: dynamic array */
|
|
ulint size) /* in: size in bytes of the element */
|
|
{
|
|
dyn_block_t* block;
|
|
ulint used;
|
|
|
|
ut_ad(arr);
|
|
ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N);
|
|
ut_ad(size <= DYN_ARRAY_DATA_SIZE);
|
|
ut_ad(size);
|
|
|
|
block = arr;
|
|
used = block->used;
|
|
|
|
if (used + size > DYN_ARRAY_DATA_SIZE) {
|
|
/* Get the last array block */
|
|
|
|
block = dyn_array_get_last_block(arr);
|
|
used = block->used;
|
|
|
|
if (used + size > DYN_ARRAY_DATA_SIZE) {
|
|
block = dyn_array_add_block(arr);
|
|
used = block->used;
|
|
}
|
|
}
|
|
|
|
block->used = used + size;
|
|
ut_ad(block->used <= DYN_ARRAY_DATA_SIZE);
|
|
|
|
return((block->data) + used);
|
|
}
|
|
|
|
/*************************************************************************
|
|
Makes room on top of a dyn array and returns a pointer to a buffer in it.
|
|
After copying the elements, the caller must close the buffer using
|
|
dyn_array_close. */
|
|
UNIV_INLINE
|
|
byte*
|
|
dyn_array_open(
|
|
/*===========*/
|
|
/* out: pointer to the buffer */
|
|
dyn_array_t* arr, /* in: dynamic array */
|
|
ulint size) /* in: size in bytes of the buffer; MUST be
|
|
smaller than DYN_ARRAY_DATA_SIZE! */
|
|
{
|
|
dyn_block_t* block;
|
|
ulint used;
|
|
|
|
ut_ad(arr);
|
|
ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N);
|
|
ut_ad(size <= DYN_ARRAY_DATA_SIZE);
|
|
ut_ad(size);
|
|
|
|
block = arr;
|
|
used = block->used;
|
|
|
|
if (used + size > DYN_ARRAY_DATA_SIZE) {
|
|
/* Get the last array block */
|
|
|
|
block = dyn_array_get_last_block(arr);
|
|
used = block->used;
|
|
|
|
if (used + size > DYN_ARRAY_DATA_SIZE) {
|
|
block = dyn_array_add_block(arr);
|
|
used = block->used;
|
|
ut_a(size <= DYN_ARRAY_DATA_SIZE);
|
|
}
|
|
}
|
|
|
|
ut_ad(block->used <= DYN_ARRAY_DATA_SIZE);
|
|
#ifdef UNIV_DEBUG
|
|
ut_ad(arr->buf_end == 0);
|
|
|
|
arr->buf_end = used + size;
|
|
#endif
|
|
return((block->data) + used);
|
|
}
|
|
|
|
/*************************************************************************
|
|
Closes the buffer returned by dyn_array_open. */
|
|
UNIV_INLINE
|
|
void
|
|
dyn_array_close(
|
|
/*============*/
|
|
dyn_array_t* arr, /* in: dynamic array */
|
|
byte* ptr) /* in: buffer space from ptr up was not used */
|
|
{
|
|
dyn_block_t* block;
|
|
|
|
ut_ad(arr);
|
|
ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N);
|
|
|
|
block = dyn_array_get_last_block(arr);
|
|
|
|
ut_ad(arr->buf_end + block->data >= ptr);
|
|
|
|
block->used = ptr - block->data;
|
|
|
|
ut_ad(block->used <= DYN_ARRAY_DATA_SIZE);
|
|
|
|
#ifdef UNIV_DEBUG
|
|
arr->buf_end = 0;
|
|
#endif
|
|
}
|
|
|
|
/****************************************************************
|
|
Returns pointer to an element in dyn array. */
|
|
UNIV_INLINE
|
|
void*
|
|
dyn_array_get_element(
|
|
/*==================*/
|
|
/* out: pointer to element */
|
|
dyn_array_t* arr, /* in: dyn array */
|
|
ulint pos) /* in: position of element as bytes
|
|
from array start */
|
|
{
|
|
dyn_block_t* block;
|
|
ulint used;
|
|
|
|
ut_ad(arr);
|
|
ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N);
|
|
|
|
/* Get the first array block */
|
|
block = dyn_array_get_first_block(arr);
|
|
|
|
if (arr->heap != NULL) {
|
|
used = dyn_block_get_used(block);
|
|
|
|
while (pos >= used) {
|
|
pos -= used;
|
|
block = UT_LIST_GET_NEXT(list, block);
|
|
ut_ad(block);
|
|
|
|
used = dyn_block_get_used(block);
|
|
}
|
|
}
|
|
|
|
ut_ad(block);
|
|
ut_ad(dyn_block_get_used(block) >= pos);
|
|
|
|
return(block->data + pos);
|
|
}
|
|
|
|
/****************************************************************
|
|
Returns the size of stored data in a dyn array. */
|
|
UNIV_INLINE
|
|
ulint
|
|
dyn_array_get_data_size(
|
|
/*====================*/
|
|
/* out: data size in bytes */
|
|
dyn_array_t* arr) /* in: dyn array */
|
|
{
|
|
dyn_block_t* block;
|
|
ulint sum = 0;
|
|
|
|
ut_ad(arr);
|
|
ut_ad(arr->magic_n == DYN_BLOCK_MAGIC_N);
|
|
|
|
if (arr->heap == NULL) {
|
|
|
|
return(arr->used);
|
|
}
|
|
|
|
/* Get the first array block */
|
|
block = dyn_array_get_first_block(arr);
|
|
|
|
while (block != NULL) {
|
|
sum += dyn_block_get_used(block);
|
|
block = dyn_array_get_next_block(arr, block);
|
|
}
|
|
|
|
return(sum);
|
|
}
|
|
|
|
/************************************************************
|
|
Pushes n bytes to a dyn array. */
|
|
UNIV_INLINE
|
|
void
|
|
dyn_push_string(
|
|
/*============*/
|
|
dyn_array_t* arr, /* in: dyn array */
|
|
const byte* str, /* in: string to write */
|
|
ulint len) /* in: string length */
|
|
{
|
|
ulint n_copied;
|
|
|
|
while (len > 0) {
|
|
if (len > DYN_ARRAY_DATA_SIZE) {
|
|
n_copied = DYN_ARRAY_DATA_SIZE;
|
|
} else {
|
|
n_copied = len;
|
|
}
|
|
|
|
memcpy(dyn_array_push(arr, n_copied), str, n_copied);
|
|
|
|
str += n_copied;
|
|
len -= n_copied;
|
|
}
|
|
}
|