Replace ararysize macro with fml::size function (flutter/engine#8975)
This is forward compatible with std::size and similar to how Chromium removed use of the arraysize macro.
This commit is contained in:
committed by
Chinmay Garde
parent
921206ba08
commit
0bca459e28
@@ -120,7 +120,6 @@ FILE: ../../../flutter/flow/texture.h
|
||||
FILE: ../../../flutter/flow/view_holder.cc
|
||||
FILE: ../../../flutter/flow/view_holder.h
|
||||
FILE: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart
|
||||
FILE: ../../../flutter/fml/arraysize.h
|
||||
FILE: ../../../flutter/fml/base32.cc
|
||||
FILE: ../../../flutter/fml/base32.h
|
||||
FILE: ../../../flutter/fml/base32_unittest.cc
|
||||
@@ -215,6 +214,7 @@ FILE: ../../../flutter/fml/platform/win/message_loop_win.h
|
||||
FILE: ../../../flutter/fml/platform/win/native_library_win.cc
|
||||
FILE: ../../../flutter/fml/platform/win/paths_win.cc
|
||||
FILE: ../../../flutter/fml/platform/win/wstring_conversion.h
|
||||
FILE: ../../../flutter/fml/size.h
|
||||
FILE: ../../../flutter/fml/string_view.cc
|
||||
FILE: ../../../flutter/fml/string_view.h
|
||||
FILE: ../../../flutter/fml/string_view_unittest.cc
|
||||
|
||||
@@ -6,7 +6,6 @@ import("//build/fuchsia/sdk.gni")
|
||||
|
||||
source_set("fml") {
|
||||
sources = [
|
||||
"arraysize.h",
|
||||
"base32.cc",
|
||||
"base32.h",
|
||||
"build_config.h",
|
||||
@@ -47,6 +46,7 @@ source_set("fml") {
|
||||
"native_library.h",
|
||||
"paths.cc",
|
||||
"paths.h",
|
||||
"size.h",
|
||||
"string_view.cc",
|
||||
"string_view.h",
|
||||
"synchronization/atomic_object.h",
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_FML_ARRAYSIZE_H_
|
||||
#define FLUTTER_FML_ARRAYSIZE_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef arraysize
|
||||
template <typename T, size_t N>
|
||||
char (&ArraySizeHelper(T (&array)[N]))[N];
|
||||
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
|
||||
#endif
|
||||
|
||||
#endif // FLUTTER_FML_ARRAYSIZE_H_
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/fml/arraysize.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/size.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace fml {
|
||||
@@ -197,7 +197,7 @@ TEST(CommandLineTest, CommmandLineFromIterators) {
|
||||
{
|
||||
static const char* const argv[] = {"my_program", "--flag=value", "arg"};
|
||||
|
||||
auto cl = CommandLineFromIterators(argv, argv + arraysize(argv));
|
||||
auto cl = CommandLineFromIterators(argv, argv + fml::size(argv));
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
EXPECT_EQ(argv[0], cl.argv0());
|
||||
std::vector<CommandLine::Option> expected_options = {
|
||||
@@ -211,7 +211,7 @@ TEST(CommandLineTest, CommmandLineFromIterators) {
|
||||
|
||||
TEST(CommandLineTest, CommandLineFromArgcArgv) {
|
||||
static const char* const argv[] = {"my_program", "--flag=value", "arg"};
|
||||
const int argc = static_cast<int>(arraysize(argv));
|
||||
const int argc = static_cast<int>(fml::size(argv));
|
||||
|
||||
auto cl = CommandLineFromArgcArgv(argc, argv);
|
||||
EXPECT_TRUE(cl.has_argv0());
|
||||
|
||||
19
engine/src/flutter/fml/size.h
Normal file
19
engine/src/flutter/fml/size.h
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_FML_SIZE_H_
|
||||
#define FLUTTER_FML_SIZE_H_
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace fml {
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
constexpr std::size_t size(T (&array)[N]) {
|
||||
return N;
|
||||
}
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_SIZE_H_
|
||||
@@ -16,12 +16,6 @@
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#ifndef arraysize
|
||||
template <typename T, size_t N>
|
||||
char (&ArraySizeHelper(T (&array)[N]))[N];
|
||||
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
|
||||
#endif
|
||||
|
||||
namespace fml {
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/common/settings.h"
|
||||
#include "flutter/fml/arraysize.h"
|
||||
#include "flutter/fml/compiler_specific.h"
|
||||
#include "flutter/fml/file.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/mapping.h"
|
||||
#include "flutter/fml/size.h"
|
||||
#include "flutter/fml/synchronization/count_down_latch.h"
|
||||
#include "flutter/fml/synchronization/thread_annotations.h"
|
||||
#include "flutter/fml/time/time_delta.h"
|
||||
@@ -292,11 +292,11 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
|
||||
args.push_back(profiler_flag);
|
||||
}
|
||||
|
||||
PushBackAll(&args, kDartLanguageArgs, arraysize(kDartLanguageArgs));
|
||||
PushBackAll(&args, kDartLanguageArgs, fml::size(kDartLanguageArgs));
|
||||
|
||||
if (IsRunningPrecompiledCode()) {
|
||||
PushBackAll(&args, kDartPrecompilationArgs,
|
||||
arraysize(kDartPrecompilationArgs));
|
||||
fml::size(kDartPrecompilationArgs));
|
||||
}
|
||||
|
||||
// Enable Dart assertions if we are not running precompiled code. We run non-
|
||||
@@ -318,42 +318,42 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
|
||||
// Debug mode uses the JIT, disable code page write protection to avoid
|
||||
// memory page protection changes before and after every compilation.
|
||||
PushBackAll(&args, kDartWriteProtectCodeArgs,
|
||||
arraysize(kDartWriteProtectCodeArgs));
|
||||
fml::size(kDartWriteProtectCodeArgs));
|
||||
#endif
|
||||
|
||||
if (enable_asserts) {
|
||||
PushBackAll(&args, kDartAssertArgs, arraysize(kDartAssertArgs));
|
||||
PushBackAll(&args, kDartAssertArgs, fml::size(kDartAssertArgs));
|
||||
}
|
||||
|
||||
if (settings_.start_paused) {
|
||||
PushBackAll(&args, kDartStartPausedArgs, arraysize(kDartStartPausedArgs));
|
||||
PushBackAll(&args, kDartStartPausedArgs, fml::size(kDartStartPausedArgs));
|
||||
}
|
||||
|
||||
if (settings_.disable_service_auth_codes) {
|
||||
PushBackAll(&args, kDartDisableServiceAuthCodesArgs,
|
||||
arraysize(kDartDisableServiceAuthCodesArgs));
|
||||
fml::size(kDartDisableServiceAuthCodesArgs));
|
||||
}
|
||||
|
||||
if (settings_.endless_trace_buffer || settings_.trace_startup) {
|
||||
// If we are tracing startup, make sure the trace buffer is endless so we
|
||||
// don't lose early traces.
|
||||
PushBackAll(&args, kDartEndlessTraceBufferArgs,
|
||||
arraysize(kDartEndlessTraceBufferArgs));
|
||||
fml::size(kDartEndlessTraceBufferArgs));
|
||||
}
|
||||
|
||||
if (settings_.trace_systrace) {
|
||||
PushBackAll(&args, kDartSystraceTraceBufferArgs,
|
||||
arraysize(kDartSystraceTraceBufferArgs));
|
||||
PushBackAll(&args, kDartTraceStreamsArgs, arraysize(kDartTraceStreamsArgs));
|
||||
fml::size(kDartSystraceTraceBufferArgs));
|
||||
PushBackAll(&args, kDartTraceStreamsArgs, fml::size(kDartTraceStreamsArgs));
|
||||
}
|
||||
|
||||
if (settings_.trace_startup) {
|
||||
PushBackAll(&args, kDartTraceStartupArgs, arraysize(kDartTraceStartupArgs));
|
||||
PushBackAll(&args, kDartTraceStartupArgs, fml::size(kDartTraceStartupArgs));
|
||||
}
|
||||
|
||||
#if defined(OS_FUCHSIA)
|
||||
PushBackAll(&args, kDartFuchsiaTraceArgs, arraysize(kDartFuchsiaTraceArgs));
|
||||
PushBackAll(&args, kDartTraceStreamsArgs, arraysize(kDartTraceStreamsArgs));
|
||||
PushBackAll(&args, kDartFuchsiaTraceArgs, fml::size(kDartFuchsiaTraceArgs));
|
||||
PushBackAll(&args, kDartTraceStreamsArgs, fml::size(kDartTraceStreamsArgs));
|
||||
#endif
|
||||
|
||||
for (size_t i = 0; i < settings_.dart_flags.size(); i++)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#include "gpu_surface_gl.h"
|
||||
|
||||
#include "flutter/fml/arraysize.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/size.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "flutter/shell/common/persistent_cache.h"
|
||||
#include "third_party/skia/include/core/SkColorFilter.h"
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/arraysize.h"
|
||||
#include "flutter/fml/command_line.h"
|
||||
#include "flutter/fml/file.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
@@ -16,6 +15,7 @@
|
||||
#include "flutter/fml/paths.h"
|
||||
#include "flutter/fml/platform/android/jni_util.h"
|
||||
#include "flutter/fml/platform/android/paths_android.h"
|
||||
#include "flutter/fml/size.h"
|
||||
#include "flutter/lib/ui/plugins/callback_cache.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/runtime/start_up.h"
|
||||
@@ -145,7 +145,7 @@ bool FlutterMain::Register(JNIEnv* env) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return env->RegisterNatives(clazz, methods, arraysize(methods)) == 0;
|
||||
return env->RegisterNatives(clazz, methods, fml::size(methods)) == 0;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
#include "flutter/assets/directory_asset_bundle.h"
|
||||
#include "flutter/assets/zip_asset_store.h"
|
||||
#include "flutter/common/settings.h"
|
||||
#include "flutter/fml/arraysize.h"
|
||||
#include "flutter/fml/file.h"
|
||||
#include "flutter/fml/platform/android/jni_util.h"
|
||||
#include "flutter/fml/platform/android/jni_weak_ref.h"
|
||||
#include "flutter/fml/platform/android/scoped_java_ref.h"
|
||||
#include "flutter/fml/size.h"
|
||||
#include "flutter/lib/ui/plugins/callback_cache.h"
|
||||
#include "flutter/runtime/dart_service_isolate.h"
|
||||
#include "flutter/shell/common/run_configuration.h"
|
||||
@@ -650,7 +650,7 @@ bool RegisterApi(JNIEnv* env) {
|
||||
};
|
||||
|
||||
if (env->RegisterNatives(g_flutter_jni_class->obj(), flutter_jni_methods,
|
||||
arraysize(flutter_jni_methods)) != 0) {
|
||||
fml::size(flutter_jni_methods)) != 0) {
|
||||
FML_LOG(ERROR) << "Failed to RegisterNatives with FlutterJNI";
|
||||
return false;
|
||||
}
|
||||
@@ -755,7 +755,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
|
||||
|
||||
if (env->RegisterNatives(g_flutter_callback_info_class->obj(),
|
||||
callback_info_methods,
|
||||
arraysize(callback_info_methods)) != 0) {
|
||||
fml::size(callback_info_methods)) != 0) {
|
||||
FML_LOG(ERROR) << "Failed to RegisterNatives with FlutterCallbackInfo";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/common/task_runners.h"
|
||||
#include "flutter/fml/arraysize.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/platform/android/jni_util.h"
|
||||
#include "flutter/fml/platform/android/scoped_java_ref.h"
|
||||
#include "flutter/fml/size.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
|
||||
namespace flutter {
|
||||
@@ -102,7 +102,7 @@ bool VsyncWaiterAndroid::Register(JNIEnv* env) {
|
||||
|
||||
FML_CHECK(g_async_wait_for_vsync_method_ != nullptr);
|
||||
|
||||
return env->RegisterNatives(clazz, methods, arraysize(methods)) == 0;
|
||||
return env->RegisterNatives(clazz, methods, fml::size(methods)) == 0;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "dart-pkg/zircon/sdk_ext/handle.h"
|
||||
#include "dart-pkg/zircon/sdk_ext/natives.h"
|
||||
#include "dart-pkg/zircon/sdk_ext/system.h"
|
||||
#include "flutter/fml/arraysize.h"
|
||||
#include "flutter/fml/size.h"
|
||||
#include "third_party/dart/runtime/include/dart_api.h"
|
||||
#include "third_party/tonic/dart_binding_macros.h"
|
||||
#include "third_party/tonic/dart_class_library.h"
|
||||
@@ -64,7 +64,7 @@ Dart_NativeFunction NativeLookup(Dart_Handle name,
|
||||
FML_DCHECK(function_name != nullptr);
|
||||
FML_DCHECK(auto_setup_scope != nullptr);
|
||||
*auto_setup_scope = true;
|
||||
size_t num_entries = arraysize(Entries);
|
||||
size_t num_entries = fml::size(Entries);
|
||||
for (size_t i = 0; i < num_entries; ++i) {
|
||||
const struct NativeEntries& entry = Entries[i];
|
||||
if (!strcmp(function_name, entry.name) &&
|
||||
@@ -78,7 +78,7 @@ Dart_NativeFunction NativeLookup(Dart_Handle name,
|
||||
}
|
||||
|
||||
const uint8_t* NativeSymbol(Dart_NativeFunction native_function) {
|
||||
size_t num_entries = arraysize(Entries);
|
||||
size_t num_entries = fml::size(Entries);
|
||||
for (size_t i = 0; i < num_entries; ++i) {
|
||||
const struct NativeEntries& entry = Entries[i];
|
||||
if (entry.function == native_function) {
|
||||
|
||||
Reference in New Issue
Block a user