Skip to content

Commit a568644

Browse files
committed
c-API: fix performace regression (missing setMaxNumberOfSymbols())
1 parent 9288cca commit a568644

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Diff for: wrappers/c/zxing-c.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
#include "ReadBarcode.h"
1010

11+
#include <cstdlib>
12+
#include <exception>
13+
#include <string>
14+
#include <string_view>
15+
#include <utility>
16+
1117
using namespace ZXing;
1218

1319
static thread_local std::string lastErrorMsg;
@@ -22,12 +28,15 @@ static char* copy(std::string_view sv)
2228
return ret;
2329
}
2430

25-
static Results ReadBarcodesAndSetLastError(const zxing_ImageView* iv, const zxing_ReaderOptions* opts)
31+
static Results ReadBarcodesAndSetLastError(const zxing_ImageView* iv, const zxing_ReaderOptions* opts, int maxSymbols)
2632
{
2733
try {
28-
if (iv)
29-
return ReadBarcodes(*iv, opts ? *opts : ReaderOptions{});
30-
else
34+
if (iv) {
35+
auto o = opts ? *opts : ReaderOptions{};
36+
if (maxSymbols)
37+
o.setMaxNumberOfSymbols(maxSymbols);
38+
return ReadBarcodes(*iv, o);
39+
} else
3140
lastErrorMsg = "ImageView param is NULL";
3241
} catch (std::exception& e) {
3342
lastErrorMsg = e.what();
@@ -233,13 +242,13 @@ bool zxing_Result_isMirrored(const zxing_Result* result)
233242

234243
zxing_Result* zxing_ReadBarcode(const zxing_ImageView* iv, const zxing_ReaderOptions* opts)
235244
{
236-
auto res = ReadBarcodesAndSetLastError(iv, opts);
245+
auto res = ReadBarcodesAndSetLastError(iv, opts, 1);
237246
return !res.empty() ? new Result(std::move(res.front())) : NULL;
238247
}
239248

240249
zxing_Results* zxing_ReadBarcodes(const zxing_ImageView* iv, const zxing_ReaderOptions* opts)
241250
{
242-
auto res = ReadBarcodesAndSetLastError(iv, opts);
251+
auto res = ReadBarcodesAndSetLastError(iv, opts, 0);
243252
return !res.empty() ? new Results(std::move(res)) : NULL;
244253
}
245254

0 commit comments

Comments
 (0)