cmm/lib/collection: remove restriction of maximum elements

webview: remove restriction of links count
eolite: remove restriction of max elements in list + 6 times speed up the open of big folders!

git-svn-id: svn://kolibrios.org@7972 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
2020-05-23 11:26:58 +00:00
parent e167f0de89
commit 8d15602e0a
20 changed files with 194 additions and 159 deletions

View File

@@ -2,89 +2,7 @@
#define INCLUDE_COLLECTION_H
#print "[include <collection.h>]\n"
/*========================================================
= =
= String =
= =
========================================================*/
struct collection
{
int realloc_size, count;
dword data_start;
dword data_size;
dword element_offset[4000];
int add();
int addn();
dword get(); //get_name_by_pos
dword get_pos_by_name();
void drop();
void increase_data_size();
dword get_last();
bool pop();
};
:void collection::increase_data_size() {
int filled_size;
if (realloc_size<4096) realloc_size = 4096;
if (!data_size) {
data_size = realloc_size;
data_start = malloc(realloc_size);
}
else {
data_size = data_size + realloc_size;
data_start = realloc(data_start, data_size);
}
}
:int collection::add(dword in) {
return addn(in, strlen(in));
}
:int collection::addn(dword in, len) {
if (count >= 4000) {
debugln("collection: more than 4000 elements!");
return 0;
}
if (element_offset[count]+len+2 > data_size) {
increase_data_size();
addn(in, len);
return 1;
}
strncpy(data_start+element_offset[count], in, len);
count++;
element_offset[count] = element_offset[count-1] + len + 1;
return 1;
}
:dword collection::get(dword pos) {
if (pos<0) || (pos>=count) return 0;
return data_start + element_offset[pos];
}
:dword collection::get_last() {
return get(count-1);
}
:dword collection::get_pos_by_name(dword name) {
dword i;
for (i=0; i<count; i++) {
if (strcmp(data_start + element_offset[i], name)==0) return i;
}
return -1;
}
:void collection::drop() {
if (data_start) free(data_start);
data_size = 0;
data_start = 0;
element_offset[count] = 0;
count = 0;
}
:bool collection::pop() {
if (count>0) count--;
}
#include "array.h"
/*========================================================
= =
@@ -100,6 +18,8 @@ struct collection_int
void alloc();
void add();
dword get();
void set();
void swap();
dword len();
dword get_last();
void pop();
@@ -128,6 +48,21 @@ struct collection_int
return ESDWORD[pos * sizeof(dword) + buf];
}
:void collection_int::set(dword pos, _in) {
while (pos >= count) add(0);
EAX = pos * sizeof(dword) + buf;
ESDWORD[EAX] = _in;
}
:void collection_int::swap(dword pos1, pos2) {
while (pos1 >= count) add(0);
while (pos2 >= count) add(0);
EAX = pos1 * sizeof(dword) + buf;
EBX = pos2 * sizeof(dword) + buf;
ESDWORD[EAX] >< ESDWORD[EBX];
}
:dword collection_int::len(dword pos) {
if (pos<0) || (pos+1>=count) return 0;
return get(pos+1) - get(pos);
@@ -145,4 +80,84 @@ struct collection_int
count = 0;
}
/*========================================================
= =
= String =
= =
========================================================*/
struct collection
{
int realloc_size, count;
dword data_start;
dword data_size;
collection_int offset;
int add();
int addn();
dword get(); //get_name_by_pos
dword get_pos_by_name();
void drop();
void increase_data_size();
dword get_last();
bool pop();
};
:void collection::increase_data_size() {
int filled_size;
if (realloc_size<4096) realloc_size = 4096;
if (!data_size) {
data_size = realloc_size;
data_start = malloc(realloc_size);
}
else {
data_size = data_size + realloc_size;
data_start = realloc(data_start, data_size);
}
}
:int collection::add(dword in) {
return addn(in, strlen(in));
}
:int collection::addn(dword in, len) {
if (offset.get(count)+len+2 > data_size) {
increase_data_size();
addn(in, len);
return 1;
}
strncpy(data_start+offset.get(count), in, len);
count++;
offset.set(count, offset.get(count-1) + len + 1);
return 1;
}
:dword collection::get(dword pos) {
if (pos<0) || (pos>=count) return 0;
return data_start + offset.get(pos);
}
:dword collection::get_last() {
return get(count-1);
}
:dword collection::get_pos_by_name(dword name) {
dword i;
for (i=0; i<count; i++) {
if (strcmp(data_start + offset.get(i), name)==0) return i;
}
return -1;
}
:void collection::drop() {
if (data_start) free(data_start);
data_size = 0;
data_start = 0;
offset.drop();
count = 0;
}
:bool collection::pop() {
if (count>0) count--;
}
#endif