Skip to content

Commit 85c08a4

Browse files
committed
Merge branch 'rewrite-export' of https://github.com/ZnPdCo/Project_LemonLime into rewrite-export
2 parents d2dede3 + 582b577 commit 85c08a4

11 files changed

Lines changed: 37 additions & 18 deletions

src/base/LemonBaseApplication.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace Lemon;
2222
auto LemonBaseApplication::Initialize() -> bool {
2323
QString errorMessage;
2424
bool canContinue;
25-
const auto hasError = parseCommandLine(&canContinue, &errorMessage);
25+
const auto hasError = ! parseCommandLine(&canContinue, &errorMessage);
2626
if (hasError) {
2727
LOG("Command line: " GEN_PAIR(errorMessage));
2828
if (! canContinue) {
@@ -48,7 +48,7 @@ auto LemonBaseApplication::Initialize() -> bool {
4848
}
4949
}
5050
LemonLimeTranslator->InstallTranslation(settings->getUiLanguage());
51-
51+
delete settings;
5252
return true;
5353
}
5454

src/base/LemonLog.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ Q_DECLARE_METATYPE(const char *)
4848

4949
namespace Lemon::base {
5050
inline std::shared_ptr<spdlog::logger> logger;
51-
inline QString tempBuffer;
52-
inline QTextStream tempStream{&tempBuffer};
5351

5452
template <LemonLogType t, typename... T> inline void log_concat(T... v) {
53+
QString tempBuffer;
54+
QTextStream tempStream{&tempBuffer};
5555
((tempStream << v << " "), ...);
5656

5757
const auto logString = tempStream.readAll().toStdString();

src/base/LemonTranslator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace Lemon::common {
5555
bool success = translatorNew->load(code + ".qm", path);
5656
if (! success) {
5757
LOG("Cannot load translation: " + code);
58+
return false;
5859
}
5960
if (pTranslator) {
6061
LOG("Removed translations");

src/base/settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ void Settings::loadSettings() {
533533
rejudgeTimes = settings.value("MaximumRejudgeTimes", 1).toInt();
534534
maxJudgingThreads = settings.value("MaximumJudgingThreads", 1).toInt();
535535
defaultInputFileExtension = settings.value("DefaultInputFileExtension", "in").toString();
536-
defaultOutputFileExtension = settings.value("DefaultOuputFileExtension", "out").toString();
536+
defaultOutputFileExtension = settings.value("DefaultOutputFileExtension", "out").toString();
537537
inputFileExtensions = settings.value("InputFileExtensions", QStringList() << "in").toStringList();
538538
outputFileExtensions =
539539
settings.value("OutputFileExtensions", QStringList() << "out" << "ans").toStringList();

src/base/settings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ class Settings {
142142
static double upperBoundForExtraTimeRatio();
143143
static QString dataPath();
144144
static QString sourcePath();
145-
static QString temporaryPath();
146145
static QString selfTestPath();
147146

148147
private:

src/core/judgingthread.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,21 @@ auto JudgingThread::getNeedRejudge() const -> bool { return needRejudge; }
9898

9999
void JudgingThread::stopJudgingSlot() { stopJudging = true; }
100100

101+
// Chunked file reader used by the line/space comparators below.
102+
//
103+
// nextUntilNewLine() / nextUntilSpace() return at most 32 chars per call --
104+
// they do NOT truncate a long line; callers must loop until eof() to consume
105+
// the whole line/token. The 32-byte cap keeps `result` (a fixed-capacity
106+
// std::string reserved at 32) from reallocating, which is the hot path of
107+
// per-test-case comparison.
101108
class BufferedStreamReader {
102109

103110
public:
104111
static const int BUFFER_SIZE = 1 << 18; // 128 KiB
105112
explicit BufferedStreamReader(const char *filename) : file(fopen(filename, "r")) {
106113
result.reserve(32);
114+
// Start with bufPos == bufEnd so the first peekChar() triggers an
115+
// fread; avoids a separate "primed?" flag.
107116
bufPos = buffer + BUFFER_SIZE;
108117
bufEnd = buffer + BUFFER_SIZE;
109118
lineNumber = 1;
@@ -140,6 +149,8 @@ auto BufferedStreamReader::peekChar() -> char {
140149
return '\0';
141150
}
142151
if (bufPos == bufEnd) {
152+
// Buffer drained -- refill. fread returning 0 means real EOF; latch it
153+
// so further peekChar() calls short-circuit without touching the FILE*.
143154
bufPos = buffer;
144155
bufEnd = buffer + fread(buffer, 1, BUFFER_SIZE, file);
145156
if (bufPos == bufEnd) {
@@ -150,6 +161,9 @@ auto BufferedStreamReader::peekChar() -> char {
150161
return *bufPos;
151162
}
152163

164+
// Consume one line terminator (\n, \r, or \r\n) if the cursor sits on one,
165+
// and bump lineNumber. Idempotent when not on a terminator -- safe to call
166+
// before each token read.
153167
void BufferedStreamReader::tryNextLine() {
154168
char c = peekChar();
155169
if (c != '\r' && c != '\n')
@@ -162,6 +176,11 @@ void BufferedStreamReader::tryNextLine() {
162176
lineNumber++;
163177
}
164178

179+
// Read up to 32 chars from the current position, stopping at any line
180+
// terminator or EOF. Does NOT consume the terminator -- the next call to
181+
// tryNextLine() (invoked at the top here) will. Returning a chunk shorter
182+
// than 32 chars is the signal that the caller has reached end-of-line/EOF;
183+
// otherwise the caller must call again to read the rest of a long line.
165184
auto BufferedStreamReader::nextUntilNewLine() -> std::string_view {
166185
result.clear();
167186
tryNextLine();
@@ -175,6 +194,10 @@ auto BufferedStreamReader::nextUntilNewLine() -> std::string_view {
175194
return result;
176195
}
177196

197+
// Skip leading whitespace (advancing lineNumber across newlines), then read
198+
// up to 32 non-space chars. Same chunked-read contract as nextUntilNewLine:
199+
// short return means token end; long tokens must be read across multiple
200+
// calls. Returns an empty view at EOF.
178201
auto BufferedStreamReader::nextUntilSpace() -> std::string_view {
179202
result.clear();
180203
for (char c = peekChar(); std::isspace(c) && ! eof(); c = peekChar())
@@ -482,7 +505,7 @@ void JudgingThread::lemonSpecialJudge(const QString &fileName) {
482505
bool flag = false;
483506

484507
while (timer.elapsed() < specialJudgeTimeLimit) {
485-
if (judge->state() != QProcess::Running) {
508+
if (judge->waitForFinished(10)) {
486509
flag = true;
487510
break;
488511
}
@@ -493,8 +516,6 @@ void JudgingThread::lemonSpecialJudge(const QString &fileName) {
493516
judge->kill();
494517
return;
495518
}
496-
497-
msleep(10);
498519
}
499520

500521
if (! flag) {
@@ -592,7 +613,7 @@ void JudgingThread::testlibSpecialJudge(const QString &fileName) {
592613
bool flag = false;
593614

594615
while (timer.elapsed() < specialJudgeTimeLimit) {
595-
if (judge->state() != QProcess::Running) {
616+
if (judge->waitForFinished(10)) {
596617
flag = true;
597618
break;
598619
}
@@ -603,8 +624,6 @@ void JudgingThread::testlibSpecialJudge(const QString &fileName) {
603624
judge->kill();
604625
return;
605626
}
606-
607-
msleep(10);
608627
}
609628

610629
if (! flag) {

src/core/processrunner_unix.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ ProcessRunnerResult UnixProcessRunner::run() {
186186
// so here it is rounded up to an integer second.
187187
long long killTimeLimit = (config.timeLimit + 999) / 1000 * 1000 + extraTime;
188188
while (timer.elapsed() <= killTimeLimit) {
189-
if (runner->state() != QProcess::Running) {
189+
if (runner->waitForFinished(10)) {
190190
isProgramFinishedInExtraTimeLimit = true;
191191
break;
192192
}
@@ -200,8 +200,6 @@ ProcessRunnerResult UnixProcessRunner::run() {
200200

201201
return res;
202202
}
203-
204-
QThread::msleep(10);
205203
}
206204

207205
if (! isProgramFinishedInExtraTimeLimit) {

src/core/processrunner_win.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ namespace {
3939
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
4040
std::mt19937 gen(std::random_device{}());
4141

42-
std::uniform_int_distribution<int> rand(0, possibleCharacters.length());
42+
std::uniform_int_distribution<int> rand(0, // [0, length of possibleCharacters - 1]
43+
possibleCharacters.length() - 1);
4344
QString randomString;
4445
for (int i = 0; i < length; ++i) {
4546
int index = rand(gen) % possibleCharacters.length();

src/core/taskjudger.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ auto TaskJudger::traditionalTaskPrepare() -> bool {
261261
bool flag = false;
262262

263263
while (timer.elapsed() < settings->getCompileTimeLimit()) {
264-
if (compilerProcess.state() != QProcess::Running) {
264+
if (compilerProcess.waitForFinished(10)) {
265265
flag = true;
266266
break;
267267
}
@@ -272,7 +272,6 @@ auto TaskJudger::traditionalTaskPrepare() -> bool {
272272
compilerProcess.kill();
273273
return false;
274274
}
275-
QThread::msleep(10);
276275
}
277276

278277
if (! flag) {

src/generalsettings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ auto GeneralSettings::checkValid() -> bool {
131131
if (ui->rejudgeTimes->text().isEmpty()) {
132132
ui->rejudgeTimes->setFocus();
133133
QMessageBox::warning(this, tr("Error"), tr("Empty maximum rejudge times!"), QMessageBox::Close);
134+
return false;
134135
}
135136

136137
return true;

0 commit comments

Comments
 (0)