MCPcopy Create free account
hub / github.com/BaseXdb/basex / store

Method store

basex-core/src/main/java/org/basex/util/History.java:109–140  ·  view source on GitHub ↗

Stores a string in the history. @param str string to be stored @param oc old caret position @param nc new caret position

(final byte[] str, final int oc, final int nc)

Source from the content-addressed store, hash-verified

107 * @param nc new caret position
108 */
109 public void store(final byte[] str, final int oc, final int nc) {
110 if(!active || str == hist[pos] || Token.eq(str, hist[pos])) return;
111
112 // merge consecutive character inputs without deletions
113 int len = str.length;
114 if(pos > 0 && saved != pos && caret[pos] == oc && oc + 1 == nc && hist[pos - 1].length < len) {
115 hist[pos] = str;
116 caret[pos] = nc;
117 return;
118 }
119
120 // summarize and limit size of new and existing entries
121 int off = pos + 1;
122 for(; off > 0 && len < MAXBYTES; off--) len += hist[off - 1].length;
123 // enough space: limit number of entries
124 if(off == 0 && pos + 1 == MAX) off = 1;
125 // remove entries
126 if(off > 0) {
127 Array.remove(hist, 0, off, MAX);
128 Array.remove(caret, 0, off, MAX);
129 saved -= off;
130 pos -= off;
131 }
132 // save new entry
133 if(pos >= 0) caret[pos] = oc;
134 if(saved > pos) saved = -1;
135 max = ++pos;
136 hist[pos] = str;
137 caret[pos] = nc;
138 // remove old entries to save memory
139 for(int p = pos + 1; p < MAX; p++) hist[p] = null;
140 }
141
142 /**
143 * Sets the saved position.

Callers 9

optimizeMethod · 0.45
setTextMethod · 0.45
commentMethod · 0.45
toCaseMethod · 0.45
sortMethod · 0.45
formatMethod · 0.45
keyPressedMethod · 0.45
keyTypedMethod · 0.45
finishMethod · 0.45

Calls 2

eqMethod · 0.95
removeMethod · 0.95

Tested by

no test coverage detected