From 408b556ed9be7fea7c77c92cc4e009a1044b9cad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 12 Feb 2001 11:25:44 +0000 Subject: [PATCH] mathed11.diff from Andre git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1484 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 5 +++++ src/mathed/array.C | 25 ++++++++++++++++--------- src/mathed/array.h | 4 ++-- src/mathed/math_iter.C | 8 ++------ 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index ff985aa5f1..4a9e426728 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,8 @@ + +2001-02-12 André Pönitz + * array.[hC]: replace private variable maxsize_ with call + to bf_.size() + 2001-02-09 Lars Gullik Bjønnes * array.h: made all variables private, removed friend, added new diff --git a/src/mathed/array.C b/src/mathed/array.C index 6c7b9a5c42..2d08fc10e3 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -40,7 +40,14 @@ void MathedArray::last(int l) int MathedArray::maxsize() const { - return maxsize_; + return static_cast(bf_.size()); +} + + +void MathedArray::need_size(int needed) +{ + if (needed >= maxsize()) + resize(needed); } @@ -51,15 +58,14 @@ void MathedArray::resize(int newsize) newsize += ARRAY_STEP - (newsize % ARRAY_STEP); bf_.resize(newsize); if (last_ >= newsize) last_ = newsize - 1; - maxsize_ = newsize; bf_[last_] = 0; } MathedArray::MathedArray(int size) { - maxsize_ = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size; - bf_.resize(maxsize_); + int newsize = (size < ARRAY_MIN_SIZE) ? ARRAY_MIN_SIZE : size; + bf_.resize(newsize); last_ = 0; } @@ -67,9 +73,7 @@ MathedArray::MathedArray(int size) void MathedArray::move(int p, int shift) { if (p <= last_) { - if (last_ + shift >= maxsize_) { - resize(last_ + shift); - } + need_size(last_ + shift); memmove(&bf_[p + shift], &bf_[p], last_ - p); last_ += shift; bf_[last_] = 0; @@ -117,8 +121,11 @@ byte & MathedArray::operator[](int i) void MathedArray::insert(int pos, byte c) { if (pos < 0) pos = last_; - if (pos >= maxsize_) - resize(maxsize_ + ARRAY_STEP); + + // I think this should be replaced by need_size(pos). Note that the + // current code looks troublesome if pos > maxsize() + ARRAY_STEP. + if (pos >= maxsize()) + resize(maxsize() + ARRAY_STEP); bf_[pos] = c; if (pos >= last_) last_ = pos + 1; diff --git a/src/mathed/array.h b/src/mathed/array.h index def0ffd185..1ee0cd7289 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -91,13 +91,13 @@ public: void resize(int newsize); /// int maxsize() const; + /// Make sure we can access at least \a needed elements + void need_size(int needed); private: /// Buffer buffer_type bf_; /// Last position inserted. int last_; - /// Max size of the array. - int maxsize_; }; #endif diff --git a/src/mathed/math_iter.C b/src/mathed/math_iter.C index b7a12f7cd3..eb64589459 100644 --- a/src/mathed/math_iter.C +++ b/src/mathed/math_iter.C @@ -194,9 +194,7 @@ void MathedIter::Insert(byte c, MathedTextCodes t) if (pos < array->last()) array->move(pos, shift); else { - if (array->last() + shift >= array->maxsize()) { - array->resize(array->last() + shift); - } + array->need_size(array->last() + shift); array->last(array->last() + shift); (*array)[array->last()] = '\0'; } @@ -230,9 +228,7 @@ void MathedIter::split(int shift) array->move(pos, shift); if (fg) (*array)[pos + shift - 1] = fcode; } else { - if (array->last() + shift >= array->maxsize()) { - array->resize(array->last() + shift); - } + array->need_size(array->last() + shift); array->last(array->last() + shift); } (*array)[array->last()] = '\0'; -- 2.39.2