Skip to content

Commit d55f462

Browse files
committed
More clang-tidy from previous commits
1 parent 025689f commit d55f462

File tree

9 files changed

+412
-531
lines changed

9 files changed

+412
-531
lines changed

api/baseapi.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,7 @@ class TESS_API TessBaseAPI {
847847
int** y1,
848848
PAGE_RES* page_res);
849849

850-
TESS_LOCAL const PAGE_RES* GetPageRes() const {
851-
return page_res_;
852-
}
850+
TESS_LOCAL const PAGE_RES* GetPageRes() const { return page_res_; }
853851
/* @} */
854852

855853

ccmain/thresholder.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ void ImageThresholder::OtsuThresholdRectToPix(Pix* src_pix,
268268
OpenclDevice od;
269269
if ((num_channels == 4 || num_channels == 1) &&
270270
od.selectedDeviceIsOpenCL() && rect_top_ == 0 && rect_left_ == 0 ) {
271-
od.ThresholdRectToPixOCL((unsigned char*)pixGetData(src_pix),
272-
num_channels, pixGetWpl(src_pix) * 4,
273-
thresholds, hi_values, out_pix /*pix_OCL*/,
274-
rect_height_, rect_width_, rect_top_, rect_left_);
271+
od.ThresholdRectToPixOCL((unsigned char*)pixGetData(src_pix), num_channels,
272+
pixGetWpl(src_pix) * 4, thresholds, hi_values,
273+
out_pix /*pix_OCL*/, rect_height_, rect_width_,
274+
rect_top_, rect_left_);
275275
} else {
276276
#endif
277277
ThresholdRectToPix(src_pix, num_channels, thresholds, hi_values, out_pix);

ccutil/strngs.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ class TESS_API STRING
147147
}
148148

149149
// returns the string data part of storage
150-
inline char* GetCStr() {
151-
return ((char *)data_) + sizeof(STRING_HEADER);
152-
}
150+
inline char* GetCStr() { return ((char*)data_) + sizeof(STRING_HEADER); }
153151

154152
inline const char* GetCStr() const {
155153
return ((const char *)data_) + sizeof(STRING_HEADER);

lstm/lstmtrainer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ void LSTMTrainer::StartSubtrainer(STRING* log_msg) {
555555
// Reduce learning rate so it doesn't diverge this time.
556556
sub_trainer_->ReduceLearningRates(this, log_msg);
557557
// If it fails again, we will wait twice as long before reverting again.
558-
int stall_offset = learning_iteration() - sub_trainer_->learning_iteration();
558+
int stall_offset =
559+
learning_iteration() - sub_trainer_->learning_iteration();
559560
stall_iteration_ = learning_iteration() + 2 * stall_offset;
560561
sub_trainer_->stall_iteration_ = stall_iteration_;
561562
// Re-save the best trainer with the new learning rates and stall iteration.

lstm/lstmtrainer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ class LSTMTrainer : public LSTMRecognizer {
113113
// previously setup UNICHARSET and UnicharCompress.
114114
// ctc_mode controls how the truth text is mapped to the network targets.
115115
// Note: Call before InitNetwork!
116-
void InitCharSet(const UNICHARSET& unicharset, const UnicharCompress& recoder);
116+
void InitCharSet(const UNICHARSET& unicharset,
117+
const UnicharCompress& recoder);
117118

118119
// Initializes the trainer with a network_spec in the network description
119120
// net_flags control network behavior according to the NetworkFlags enum.

opencl/opencl_device_selection.h

+31-34
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ typedef struct {
6868
typedef ds_status (*ds_score_release)(void* score);
6969
static ds_status releaseDSProfile(ds_profile* profile, ds_score_release sr) {
7070
ds_status status = DS_SUCCESS;
71-
if (profile!=nullptr) {
72-
if (profile->devices!=nullptr && sr!=nullptr) {
71+
if (profile != nullptr) {
72+
if (profile->devices != nullptr && sr != nullptr) {
7373
unsigned int i;
7474
for (i = 0; i < profile->numDevices; i++) {
7575
free(profile->devices[i].oclDeviceName);
@@ -90,18 +90,16 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
9090
int numDevices;
9191
cl_uint numPlatforms;
9292
cl_platform_id* platforms = nullptr;
93-
cl_device_id* devices = nullptr;
93+
cl_device_id* devices = nullptr;
9494
ds_status status = DS_SUCCESS;
9595
unsigned int next;
9696
unsigned int i;
9797

98-
if (p == nullptr)
99-
return DS_INVALID_PROFILE;
98+
if (p == nullptr) return DS_INVALID_PROFILE;
10099

101100
ds_profile* profile = (ds_profile*)malloc(sizeof(ds_profile));
102-
if (profile == nullptr)
103-
return DS_MEMORY_ERROR;
104-
101+
if (profile == nullptr) return DS_MEMORY_ERROR;
102+
105103
memset(profile, 0, sizeof(ds_profile));
106104

107105
clGetPlatformIDs(0, nullptr, &numPlatforms);
@@ -131,7 +129,8 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
131129
}
132130

133131
profile->numDevices = numDevices+1; // +1 to numDevices to include the native CPU
134-
profile->devices = (ds_device*)malloc(profile->numDevices*sizeof(ds_device));
132+
profile->devices =
133+
(ds_device*)malloc(profile->numDevices * sizeof(ds_device));
135134
if (profile->devices == nullptr) {
136135
profile->numDevices = 0;
137136
status = DS_MEMORY_ERROR;
@@ -151,14 +150,14 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
151150
profile->devices[next].type = DS_DEVICE_OPENCL_DEVICE;
152151
profile->devices[next].oclDeviceID = devices[j];
153152

154-
clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DEVICE_NAME
155-
, DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
153+
clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DEVICE_NAME,
154+
DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
156155
length = strlen(buffer);
157156
profile->devices[next].oclDeviceName = (char*)malloc(length+1);
158157
memcpy(profile->devices[next].oclDeviceName, buffer, length+1);
159158

160-
clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DRIVER_VERSION
161-
, DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
159+
clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DRIVER_VERSION,
160+
DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
162161
length = strlen(buffer);
163162
profile->devices[next].oclDriverVersion = (char*)malloc(length+1);
164163
memcpy(profile->devices[next].oclDriverVersion, buffer, length+1);
@@ -213,8 +212,7 @@ static ds_status profileDevices(ds_profile* profile,
213212

214213
switch (type) {
215214
case DS_EVALUATE_NEW_ONLY:
216-
if (profile->devices[i].score != nullptr)
217-
break;
215+
if (profile->devices[i].score != nullptr) break;
218216
// else fall through
219217
case DS_EVALUATE_ALL:
220218
evaluatorStatus = evaluator(profile->devices+i, evaluatorData);
@@ -260,11 +258,10 @@ static ds_status writeProfileToFile(ds_profile* profile,
260258
const char* file) {
261259
ds_status status = DS_SUCCESS;
262260

263-
if (profile == nullptr)
264-
return DS_INVALID_PROFILE;
261+
if (profile == nullptr) return DS_INVALID_PROFILE;
265262

266263
FILE* profileFile = fopen(file, "wb");
267-
if (profileFile==nullptr) {
264+
if (profileFile == nullptr) {
268265
status = DS_FILE_ERROR;
269266
}
270267
else {
@@ -327,7 +324,8 @@ static ds_status writeProfileToFile(ds_profile* profile,
327324
fwrite(DS_TAG_SCORE, sizeof(char), strlen(DS_TAG_SCORE), profileFile);
328325
status = serializer(profile->devices+i, &serializedScore,
329326
&serializedScoreSize);
330-
if (status == DS_SUCCESS && serializedScore!=nullptr && serializedScoreSize > 0) {
327+
if (status == DS_SUCCESS && serializedScore != nullptr &&
328+
serializedScoreSize > 0) {
331329
fwrite(serializedScore, sizeof(char), serializedScoreSize, profileFile);
332330
free(serializedScore);
333331
}
@@ -349,15 +347,15 @@ static ds_status readProFile(const char* fileName, char** content,
349347
*content = nullptr;
350348

351349
FILE* input = fopen(fileName, "rb");
352-
if(input == nullptr) {
350+
if (input == nullptr) {
353351
return DS_FILE_ERROR;
354352
}
355353

356354
fseek(input, 0L, SEEK_END);
357355
size = ftell(input);
358356
rewind(input);
359357
char* binary = (char*)malloc(size);
360-
if(binary == nullptr) {
358+
if (binary == nullptr) {
361359
fclose(input);
362360
return DS_FILE_ERROR;
363361
}
@@ -403,8 +401,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
403401
const char* contentEnd = nullptr;
404402
size_t contentSize;
405403

406-
if (profile==nullptr)
407-
return DS_INVALID_PROFILE;
404+
if (profile == nullptr) return DS_INVALID_PROFILE;
408405

409406
status = readProFile(file, &contentStart, &contentSize);
410407
if (status == DS_SUCCESS) {
@@ -426,7 +423,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
426423
dataStart += strlen(DS_TAG_VERSION);
427424

428425
dataEnd = findString(dataStart, contentEnd, DS_TAG_VERSION_END);
429-
if (dataEnd==nullptr) {
426+
if (dataEnd == nullptr) {
430427
status = DS_PROFILE_FILE_ERROR;
431428
goto cleanup;
432429
}
@@ -458,27 +455,27 @@ static ds_status readProfileFromFile(ds_profile* profile,
458455
const char* deviceDriverEnd;
459456

460457
dataStart = findString(currentPosition, contentEnd, DS_TAG_DEVICE);
461-
if (dataStart==nullptr) {
458+
if (dataStart == nullptr) {
462459
// nothing useful remain, quit...
463460
break;
464461
}
465462
dataStart+=strlen(DS_TAG_DEVICE);
466463
dataEnd = findString(dataStart, contentEnd, DS_TAG_DEVICE_END);
467-
if (dataEnd==nullptr) {
464+
if (dataEnd == nullptr) {
468465
status = DS_PROFILE_FILE_ERROR;
469466
goto cleanup;
470467
}
471468

472469
// parse the device type
473470
deviceTypeStart = findString(dataStart, contentEnd, DS_TAG_DEVICE_TYPE);
474-
if (deviceTypeStart==nullptr) {
471+
if (deviceTypeStart == nullptr) {
475472
status = DS_PROFILE_FILE_ERROR;
476473
goto cleanup;
477474
}
478475
deviceTypeStart+=strlen(DS_TAG_DEVICE_TYPE);
479476
deviceTypeEnd = findString(deviceTypeStart, contentEnd,
480477
DS_TAG_DEVICE_TYPE_END);
481-
if (deviceTypeEnd==nullptr) {
478+
if (deviceTypeEnd == nullptr) {
482479
status = DS_PROFILE_FILE_ERROR;
483480
goto cleanup;
484481
}
@@ -489,29 +486,29 @@ static ds_status readProfileFromFile(ds_profile* profile,
489486
if (deviceType == DS_DEVICE_OPENCL_DEVICE) {
490487

491488
deviceNameStart = findString(dataStart, contentEnd, DS_TAG_DEVICE_NAME);
492-
if (deviceNameStart==nullptr) {
489+
if (deviceNameStart == nullptr) {
493490
status = DS_PROFILE_FILE_ERROR;
494491
goto cleanup;
495492
}
496493
deviceNameStart+=strlen(DS_TAG_DEVICE_NAME);
497494
deviceNameEnd = findString(deviceNameStart, contentEnd,
498495
DS_TAG_DEVICE_NAME_END);
499-
if (deviceNameEnd==nullptr) {
496+
if (deviceNameEnd == nullptr) {
500497
status = DS_PROFILE_FILE_ERROR;
501498
goto cleanup;
502499
}
503500

504501

505502
deviceDriverStart = findString(dataStart, contentEnd,
506503
DS_TAG_DEVICE_DRIVER_VERSION);
507-
if (deviceDriverStart==nullptr) {
504+
if (deviceDriverStart == nullptr) {
508505
status = DS_PROFILE_FILE_ERROR;
509506
goto cleanup;
510507
}
511508
deviceDriverStart+=strlen(DS_TAG_DEVICE_DRIVER_VERSION);
512509
deviceDriverEnd = findString(deviceDriverStart, contentEnd,
513510
DS_TAG_DEVICE_DRIVER_VERSION_END);
514-
if (deviceDriverEnd ==nullptr) {
511+
if (deviceDriverEnd == nullptr) {
515512
status = DS_PROFILE_FILE_ERROR;
516513
goto cleanup;
517514
}
@@ -532,7 +529,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
532529
&& strncmp(profile->devices[i].oclDriverVersion, deviceDriverStart,
533530
driverVersionLength)==0) {
534531
deviceScoreStart = findString(dataStart, contentEnd, DS_TAG_SCORE);
535-
if (deviceNameStart==nullptr) {
532+
if (deviceNameStart == nullptr) {
536533
status = DS_PROFILE_FILE_ERROR;
537534
goto cleanup;
538535
}
@@ -554,7 +551,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
554551
for (i = 0; i < profile->numDevices; i++) {
555552
if (profile->devices[i].type == DS_DEVICE_NATIVE_CPU) {
556553
deviceScoreStart = findString(dataStart, contentEnd, DS_TAG_SCORE);
557-
if (deviceScoreStart==nullptr) {
554+
if (deviceScoreStart == nullptr) {
558555
status = DS_PROFILE_FILE_ERROR;
559556
goto cleanup;
560557
}

0 commit comments

Comments
 (0)