Skip to content

Commit

Permalink
improve cubestd sortlist style, size_t usage
Browse files Browse the repository at this point in the history
  • Loading branch information
no-lex committed May 29, 2024
1 parent 35aae2a commit 742e03d
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/engine/interface/cubestd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,48 +1085,48 @@ static void findfile_(char *name)
);
}

struct SortItem
void sortlist(char *list, ident *x, ident *y, uint *body, uint *unique)
{
const char *str, *quotestart, *quoteend;

int quotelength() const
struct SortItem
{
return static_cast<int>(quoteend-quotestart);
}
};

struct SortFunction
{
ident *x, *y;
uint *body;
const char *str, *quotestart, *quoteend;

bool operator()(const SortItem &xval, const SortItem &yval)
{
if(x->valtype != Value_CString)
size_t quotelength() const
{
x->valtype = Value_CString;
return static_cast<size_t>(quoteend-quotestart);
}
cleancode(*x);
x->val.code = reinterpret_cast<const uint *>(xval.str);
if(y->valtype != Value_CString)
};

struct SortFunction
{
ident *x, *y;
uint *body;

bool operator()(const SortItem &xval, const SortItem &yval)
{
y->valtype = Value_CString;
if(x->valtype != Value_CString)
{
x->valtype = Value_CString;
}
cleancode(*x);
x->val.code = reinterpret_cast<const uint *>(xval.str);
if(y->valtype != Value_CString)
{
y->valtype = Value_CString;
}
cleancode(*y);
y->val.code = reinterpret_cast<const uint *>(yval.str);
return executebool(body);
}
cleancode(*y);
y->val.code = reinterpret_cast<const uint *>(yval.str);
return executebool(body);
}
};
};

void sortlist(char *list, ident *x, ident *y, uint *body, uint *unique)
{
if(x == y || x->type != Id_Alias || y->type != Id_Alias)
{
return;
}
std::vector<SortItem> items;
int clen = std::strlen(list),
total = 0;
size_t clen = std::strlen(list),
total = 0;
char *cstr = newstring(list, clen);
const char *curlist = list,
*start, *end, *quotestart, *quoteend;
Expand All @@ -1147,8 +1147,8 @@ void sortlist(char *list, ident *x, ident *y, uint *body, uint *unique)
x->flags &= ~Idf_Unknown;
pusharg(*y, NullVal(), ystack);
y->flags &= ~Idf_Unknown;
int totalunique = total;
uint numunique = items.size();
size_t totalunique = total,
numunique = items.size();
if(body)
{
SortFunction f = { x, y, body };
Expand Down Expand Up @@ -1200,7 +1200,7 @@ void sortlist(char *list, ident *x, ident *y, uint *body, uint *unique)
poparg(*x);
poparg(*y);
char *sorted = cstr;
int sortedlen = totalunique + std::max(static_cast<int>(numunique - 1), 0);
size_t sortedlen = totalunique + std::max(numunique - 1, size_t(0));
if(clen < sortedlen)
{
delete[] cstr;
Expand Down

0 comments on commit 742e03d

Please sign in to comment.