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

Commit 96cadec

Browse files
committed
Address comments
1 parent 35d4b61 commit 96cadec

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,29 @@
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+
template <typename T, class = std::enable_if_t<std::is_integral_v<T>>>
3131
constexpr T ByteSwap(T n) {
3232
if constexpr (sizeof(T) == 1) {
3333
return n;
3434
} else if constexpr (sizeof(T) == 2) {
35-
return (T)BYTESWAP16((uint16_t)n);
35+
return (T)FML_BYTESWAP_16((uint16_t)n);
3636
} else if constexpr (sizeof(T) == 4) {
37-
return (T)BYTESWAP32((uint32_t)n);
37+
return (T)FML_BYTESWAP_32((uint32_t)n);
3838
} else if constexpr (sizeof(T) == 8) {
39-
return (T)BYTESWAP64((uint64_t)n);
39+
return (T)FML_BYTESWAP_64((uint32_t)n);
4040
} else {
4141
static_assert(!sizeof(T), "Unsupported size");
4242
}

0 commit comments

Comments
 (0)