Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e85b19d

Browse files
committed
Address comments
1 parent 35d4b61 commit e85b19d

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ FILE: ../../../flutter/fml/dart/dart_converter.h
176176
FILE: ../../../flutter/fml/delayed_task.cc
177177
FILE: ../../../flutter/fml/delayed_task.h
178178
FILE: ../../../flutter/fml/eintr_wrapper.h
179+
FILE: ../../../flutter/fml/endianness.cc
179180
FILE: ../../../flutter/fml/endianness.h
180181
FILE: ../../../flutter/fml/endianness_unittests.cc
181182
FILE: ../../../flutter/fml/file.cc

fml/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ source_set("fml") {
2121
"delayed_task.cc",
2222
"delayed_task.h",
2323
"eintr_wrapper.h",
24+
"endianness.cc",
25+
"endianness.h",
2426
"file.cc",
2527
"file.h",
2628
"hash_combine.h",

fml/endianness.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/fml/endianness.h"

fml/endianness.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,30 @@
1414
#include "flutter/fml/build_config.h"
1515

1616
// Compiler intrinsics for flipping endianness.
17-
#define BYTESWAP16(n) __builtin_bswap16(n)
18-
#define BYTESWAP32(n) __builtin_bswap32(n)
19-
#define BYTESWAP64(n) __builtin_bswap64(n)
17+
#define FML_BYTESWAP_16(n) __builtin_bswap16(n)
18+
#define FML_BYTESWAP_32(n) __builtin_bswap32(n)
19+
#define FML_BYTESWAP_64(n) __builtin_bswap64(n)
2020

2121
#if defined(_MSC_VER)
22-
#define BYTESWAP16(n) _byteswap_ushort(n)
23-
#define BYTESWAP32(n) _byteswap_ulong(n)
24-
#define BYTESWAP64(n) _byteswap_uint64(n)
22+
#define FML_BYTESWAP_16(n) _byteswap_ushort(n)
23+
#define FML_BYTESWAP_32(n) _byteswap_ulong(n)
24+
#define FML_BYTESWAP_64(n) _byteswap_uint64(n)
2525
#endif
2626

2727
namespace fml {
2828

2929
/// @brief Flips the endianness of the given value.
30-
template <typename T>
30+
/// The given value must be an integral type of size 1, 2, 4, or 8.
31+
template <typename T, class = std::enable_if_t<std::is_integral_v<T>>>
3132
constexpr T ByteSwap(T n) {
3233
if constexpr (sizeof(T) == 1) {
3334
return n;
3435
} else if constexpr (sizeof(T) == 2) {
35-
return (T)BYTESWAP16((uint16_t)n);
36+
return (T)FML_BYTESWAP_16((uint16_t)n);
3637
} else if constexpr (sizeof(T) == 4) {
37-
return (T)BYTESWAP32((uint32_t)n);
38+
return (T)FML_BYTESWAP_32((uint32_t)n);
3839
} else if constexpr (sizeof(T) == 8) {
39-
return (T)BYTESWAP64((uint64_t)n);
40+
return (T)FML_BYTESWAP_64((uint64_t)n);
4041
} else {
4142
static_assert(!sizeof(T), "Unsupported size");
4243
}
@@ -45,7 +46,8 @@ constexpr T ByteSwap(T n) {
4546
/// @brief Convert a known big endian value to match the endianness of the
4647
/// current architecture. This is effectively a cross platform
4748
/// ntohl/ntohs (as network byte order is always Big Endian).
48-
template <typename T>
49+
/// The given value must be an integral type of size 1, 2, 4, or 8.
50+
template <typename T, class = std::enable_if_t<std::is_integral_v<T>>>
4951
constexpr T BigEndianToArch(T n) {
5052
#if ARCH_CPU_LITTLE_ENDIAN
5153
return ByteSwap<T>(n);
@@ -56,7 +58,8 @@ constexpr T BigEndianToArch(T n) {
5658

5759
/// @brief Convert a known little endian value to match the endianness of the
5860
/// current architecture.
59-
template <typename T>
61+
/// The given value must be an integral type of size 1, 2, 4, or 8.
62+
template <typename T, class = std::enable_if_t<std::is_integral_v<T>>>
6063
constexpr T LittleEndianToArch(T n) {
6164
#if !ARCH_CPU_LITTLE_ENDIAN
6265
return ByteSwap<T>(n);

0 commit comments

Comments
 (0)