]> git.lyx.org Git - features.git/commitdiff
mathed11.diff from Andre
authorLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 12 Feb 2001 11:25:44 +0000 (11:25 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 12 Feb 2001 11:25:44 +0000 (11:25 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1484 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/array.C
src/mathed/array.h
src/mathed/math_iter.C

index ff985aa5f188eb9adf5c024677151e6c8ba1b448..4a9e426728383cb719915b9e71dafd83e532067c 100644 (file)
@@ -1,3 +1,8 @@
+
+2001-02-12  André Pönitz  <poenitz@htwm.de>
+       * array.[hC]: replace private variable maxsize_ with call 
+       to bf_.size() 
+
 2001-02-09  Lars Gullik Bjønnes  <larsbj@lyx.org>
 
        * array.h: made all variables private, removed friend, added new
index 6c7b9a5c42ce3dc97afc542611603728c0afc7c1..2d08fc10e39a23915856563da2b43d01755e1e1a 100644 (file)
@@ -40,7 +40,14 @@ void MathedArray::last(int l)
 
 int MathedArray::maxsize() const
 {
-       return maxsize_;
+       return static_cast<int>(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;
index def0ffd18586626f6eadc71505ee317e30c51a5c..1ee0cd7289dfb2fbb668856e74f852af4415edb8 100644 (file)
@@ -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
index b7a12f7cd33440e4652d522a72832d433736f991..eb6458945916e93abe645edc7b7de7a2e79d8848 100644 (file)
@@ -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';