From 9bfa18c4cc5688627fe45cb81a160c9c01f17baa Mon Sep 17 00:00:00 2001 From: Alessandro <66976091+alessandromrc@users.noreply.github.com> Date: Tue, 26 Mar 2024 21:41:16 +0100 Subject: [PATCH 1/3] Performance Improvement when writing --- binding.gyp | 6 ++++++ src/line.cc | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/binding.gyp b/binding.gyp index f3a38a4..21943d5 100644 --- a/binding.gyp +++ b/binding.gyp @@ -16,6 +16,12 @@ "libraries" : [ "-lgpiod" ], + "cflags": [ + "-O3" + ], + "lflags": [ + "-flto" + ] }] ] } diff --git a/src/line.cc b/src/line.cc index b69c11d..5254b13 100644 --- a/src/line.cc +++ b/src/line.cc @@ -112,12 +112,13 @@ NAN_METHOD(Line::getValue) { NAN_METHOD(Line::setValue) { Line *obj = Nan::ObjectWrap::Unwrap(info.This()); if (!obj->line) { - Nan::ThrowError("::setValue() for line==NULL"); - return; + return Nan::ThrowError("setValue() called for null line."); + } + + uint32_t value = Nan::To(info[0]).FromJust(); + if (gpiod_line_set_value(obj->line, value) == -1) { + return Nan::ThrowError("setValue() failed."); } - unsigned int value = Nan::To(info[0]).FromJust(); - if (-1 == gpiod_line_set_value(obj->getNativeLine(), value)) - Nan::ThrowError("::setValue() failed"); } NAN_METHOD(Line::requestInputMode) { From 54aa0d6526a540f0c1cefb27a6288d5d5c3dc524 Mon Sep 17 00:00:00 2001 From: alessandromrc <66976091+alessandromrc@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:40:56 +0100 Subject: [PATCH 2/3] Use v8 to get context for even more speed --- src/line.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/line.cc b/src/line.cc index 5254b13..da718d9 100644 --- a/src/line.cc +++ b/src/line.cc @@ -111,11 +111,8 @@ NAN_METHOD(Line::getValue) { NAN_METHOD(Line::setValue) { Line *obj = Nan::ObjectWrap::Unwrap(info.This()); - if (!obj->line) { - return Nan::ThrowError("setValue() called for null line."); - } - - uint32_t value = Nan::To(info[0]).FromJust(); + v8::Local context = Nan::GetCurrentContext(); + uint32_t value = info[0]->Uint32Value(context).FromJust(); if (gpiod_line_set_value(obj->line, value) == -1) { return Nan::ThrowError("setValue() failed."); } From 69073067f6734a7a3473aaf75eab9d4362faf44b Mon Sep 17 00:00:00 2001 From: alessandromrc <66976091+alessandromrc@users.noreply.github.com> Date: Wed, 27 Mar 2024 00:10:43 +0100 Subject: [PATCH 3/3] Get current Line obj directly from the holder --- src/line.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/line.cc b/src/line.cc index da718d9..0d32499 100644 --- a/src/line.cc +++ b/src/line.cc @@ -110,7 +110,7 @@ NAN_METHOD(Line::getValue) { } NAN_METHOD(Line::setValue) { - Line *obj = Nan::ObjectWrap::Unwrap(info.This()); + Line *obj = ObjectWrap::Unwrap(info.Holder()); v8::Local context = Nan::GetCurrentContext(); uint32_t value = info[0]->Uint32Value(context).FromJust(); if (gpiod_line_set_value(obj->line, value) == -1) {