Skip to content

Commit b2d90b5

Browse files
committed
fix: Avoid extra memcpy in write callback
fix: Avoid extra cast in signal_connect
1 parent 2feeb9a commit b2d90b5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

examples/streaming-bench.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@
122122

123123
$doBenchmark();
124124

125-
echo "=== NOW NO CACHE ===" . PHP_EOL;
126-
127-
Config::cacheSetMax(0);
128-
Config::cacheSetMaxFiles(0);
129-
Config::cacheSetMaxMem(0);
130-
131-
$doBenchmark();
125+
//echo "=== NOW NO CACHE ===" . PHP_EOL;
126+
//
127+
//Config::cacheSetMax(0);
128+
//Config::cacheSetMaxFiles(0);
129+
//Config::cacheSetMaxMem(0);
130+
//
131+
//$doBenchmark();

src/GObject.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ public function signalConnect(string $name, Closure $callback): void
171171
$bufferLength = (int) FFI::gobject()->g_value_get_int64(\FFI::addr($params[2]));
172172
$buffer = \FFI::string($bufferPointer, $bufferLength);
173173
$returnBufferLength = $callback($buffer);
174-
\FFI::memcpy($bufferPointer, $buffer, $returnBufferLength);
175174
FFI::gobject()->g_value_set_int64($returnValue, $returnBufferLength);
176175
};
177176
$marshalers['finish'] = static function (
@@ -211,10 +210,9 @@ public function signalConnect(string $name, Closure $callback): void
211210
throw new Exception("unsupported signal $name");
212211
}
213212

214-
$go = \FFI::cast(FFI::ctypes('GObject'), $this->pointer);
215213
$gc = FFI::gobject()->g_closure_new_simple(\FFI::sizeof(FFI::ctypes('GClosure')), null);
216214
$gc->marshal = $marshalers[$name];
217-
FFI::gobject()->g_signal_connect_closure($go, $name, $gc, 0);
215+
FFI::gobject()->g_signal_connect_closure($this->pointer, $name, $gc, 0);
218216
}
219217
}
220218

0 commit comments

Comments
 (0)