dart external function
檢視源碼時看到了
external bool identical(Object a, Object b)
,發現關聯不到實作,随手查查資料發現這是個複雜的問題 - -
簡單來說就是隻聲明方法,具體實作由外部提供,通常是不同的平台 runtime,類似 Java 的 native 方法。
而 core.identical.identical 的實作在
https://github.com/dart-lang/sdk/blob/master/runtime/lib/identical_patch.dart
@patch
@pragma("vm:exact-result-type", bool)
bool identical(Object a, Object b) native "Identical_comparison";
調用了 native 的 identical.cc 的 Identical_comparison
DEFINE_NATIVE_ENTRY(Identical_comparison, 0, 2) {
GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0));
GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1));
const bool is_identical = a.IsIdenticalTo(b);
return Bool::Get(is_identical).raw();
}
具體怎麼關聯上還是個迷 - -
參考
https://stackoverflow.com/questions/24929659/what-does-external-mean-in-dart
https://stackoverflow.com/questions/27453002/example-of-how-to-link-external-function-to-its-implementation
https://github.com/dart-lang/sdk/issues/4300