Remove fxcrt::ByteSwapTo* functions
There are no callers, except for unit tests. All other callers are using
the From* aliases instead. So just merge them together.
Change-Id: I1e64c7e1029f3bb8e7f8434de0226611cae029c8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/116575
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/byteorder.h b/core/fxcrt/byteorder.h
index 0002058..24dd059 100644
--- a/core/fxcrt/byteorder.h
+++ b/core/fxcrt/byteorder.h
@@ -49,11 +49,11 @@
} // namespace internal
-// NOTE: Prefer *Swap*() methods when data is known to be aligned.
+// NOTE: Prefer From*() methods when data is known to be aligned.
// Converts the bytes in |x| from host order (endianness) to little endian, and
// returns the result.
-inline uint16_t ByteSwapToLE16(uint16_t x) {
+inline uint16_t FromLE16(uint16_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
return x;
#else
@@ -61,7 +61,7 @@
#endif
}
-inline uint32_t ByteSwapToLE32(uint32_t x) {
+inline uint32_t FromLE32(uint32_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
return x;
#else
@@ -71,36 +71,20 @@
// Converts the bytes in |x| from host order (endianness) to big endian, and
// returns the result.
-inline uint16_t ByteSwapToBE16(uint16_t x) {
-#if defined(ARCH_CPU_LITTLE_ENDIAN)
- return internal::ByteSwap(x);
-#else
- return x;
-#endif
-}
-
-inline uint32_t ByteSwapToBE32(uint32_t x) {
-#if defined(ARCH_CPU_LITTLE_ENDIAN)
- return internal::ByteSwap(x);
-#else
- return x;
-#endif
-}
-
-// NOTE: These methods exist to improve readability by putting the word "From"
-// into the name, otherwise it is less clear that `x = ByteSwapToLE16(y)` gives
-// `x` in the native representation when `y` is in a LE representation.
-inline uint16_t FromLE16(uint16_t x) {
- return ByteSwapToLE16(x);
-}
-inline uint32_t FromLE32(uint16_t x) {
- return ByteSwapToLE32(x);
-}
inline uint16_t FromBE16(uint16_t x) {
- return ByteSwapToBE16(x);
+#if defined(ARCH_CPU_LITTLE_ENDIAN)
+ return internal::ByteSwap(x);
+#else
+ return x;
+#endif
}
-inline uint32_t FromBE32(uint16_t x) {
- return ByteSwapToBE32(x);
+
+inline uint32_t FromBE32(uint32_t x) {
+#if defined(ARCH_CPU_LITTLE_ENDIAN)
+ return internal::ByteSwap(x);
+#else
+ return x;
+#endif
}
// Transfer to/from spans irrespective of alignments.
diff --git a/core/fxcrt/byteorder_unittest.cpp b/core/fxcrt/byteorder_unittest.cpp
index d71ae61..0b43385 100644
--- a/core/fxcrt/byteorder_unittest.cpp
+++ b/core/fxcrt/byteorder_unittest.cpp
@@ -19,35 +19,35 @@
namespace fxcrt {
-TEST(ByteOrder, ByteSwapToLE16) {
+TEST(ByteOrder, FromLE16) {
// Since there are so few values, test them all.
for (uint32_t v = 0; v < 0x10000; ++v) {
const uint16_t v16 = v;
uint16_t expected = GetUInt16LSBFirst(pdfium::byte_span_from_ref(v16));
- EXPECT_EQ(expected, ByteSwapToLE16(v16)) << v;
+ EXPECT_EQ(expected, FromLE16(v16)) << v;
}
}
-TEST(ByteOrder, ByteSwapToLE32) {
+TEST(ByteOrder, FromLE32) {
for (uint32_t v : kTestValues32) {
uint32_t expected = GetUInt32LSBFirst(pdfium::byte_span_from_ref(v));
- EXPECT_EQ(expected, ByteSwapToLE32(v)) << v;
+ EXPECT_EQ(expected, FromLE32(v)) << v;
}
}
-TEST(ByteOrder, ByteSwapToBE16) {
+TEST(ByteOrder, FromBE16) {
// Since there are so few values, test them all.
for (uint32_t v = 0; v < 0x10000; ++v) {
const uint16_t v16 = v;
uint16_t expected = GetUInt16MSBFirst(pdfium::byte_span_from_ref(v16));
- EXPECT_EQ(expected, ByteSwapToBE16(v16)) << v;
+ EXPECT_EQ(expected, FromBE16(v16)) << v;
}
}
-TEST(ByteOrder, ByteSwapToBE32) {
+TEST(ByteOrder, FromBE32) {
for (uint32_t v : kTestValues32) {
uint32_t expected = GetUInt32MSBFirst(pdfium::byte_span_from_ref(v));
- EXPECT_EQ(expected, ByteSwapToBE32(v)) << v;
+ EXPECT_EQ(expected, FromBE32(v)) << v;
}
}