From 86ab9ff8a2eb283cb19045a93d2fc37a940ecedb Mon Sep 17 00:00:00 2001
From: Elliott Hughes <enh@google.com>
Date: Wed, 5 Sep 2018 12:13:11 -0700
Subject: [PATCH] adb: static constexpr.

Also inline some single-use constants.

Bug: N/A
Test: ran tests
Change-Id: I1ac028667772599291da402120a270d0667fed04
---
 adb/adb_utils.cpp          |  4 ++--
 adb/client/commandline.cpp |  7 +++----
 adb/client/fastdeploy.cpp  |  4 ++--
 adb/transport.cpp          | 10 ++--------
 adb/transport_local.cpp    |  4 ++--
 5 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/adb/adb_utils.cpp b/adb/adb_utils.cpp
index ffac315b37..35017f0e31 100644
--- a/adb/adb_utils.cpp
+++ b/adb/adb_utils.cpp
@@ -49,9 +49,9 @@
 
 
 #if defined(_WIN32)
-constexpr char kNullFileName[] = "NUL";
+static constexpr char kNullFileName[] = "NUL";
 #else
-constexpr char kNullFileName[] = "/dev/null";
+static constexpr char kNullFileName[] = "/dev/null";
 #endif
 
 void close_stdin() {
diff --git a/adb/client/commandline.cpp b/adb/client/commandline.cpp
index 451422fb05..a5cfd7f1ca 100644
--- a/adb/client/commandline.cpp
+++ b/adb/client/commandline.cpp
@@ -354,8 +354,7 @@ static void stdinout_raw_epilogue(int inFd, int outFd, int old_stdin_mode, int o
 }
 
 void copy_to_file(int inFd, int outFd) {
-    constexpr size_t BUFSIZE = 32 * 1024;
-    std::vector<char> buf(BUFSIZE);
+    std::vector<char> buf(32 * 1024);
     int len;
     long total = 0;
     int old_stdin_mode = -1;
@@ -367,9 +366,9 @@ void copy_to_file(int inFd, int outFd) {
 
     while (true) {
         if (inFd == STDIN_FILENO) {
-            len = unix_read(inFd, buf.data(), BUFSIZE);
+            len = unix_read(inFd, buf.data(), buf.size());
         } else {
-            len = adb_read(inFd, buf.data(), BUFSIZE);
+            len = adb_read(inFd, buf.data(), buf.size());
         }
         if (len == 0) {
             D("copy_to_file() : read 0 bytes; exiting");
diff --git a/adb/client/fastdeploy.cpp b/adb/client/fastdeploy.cpp
index fda388962e..3b05661020 100644
--- a/adb/client/fastdeploy.cpp
+++ b/adb/client/fastdeploy.cpp
@@ -25,9 +25,9 @@
 #include "fastdeploycallbacks.h"
 #include "utils/String16.h"
 
-const long kRequiredAgentVersion = 0x00000001;
+static constexpr long kRequiredAgentVersion = 0x00000001;
 
-const char* kDeviceAgentPath = "/data/local/tmp/";
+static constexpr const char* kDeviceAgentPath = "/data/local/tmp/";
 
 long get_agent_version() {
     std::vector<char> versionOutputBuffer;
diff --git a/adb/transport.cpp b/adb/transport.cpp
index 239403a83f..95df49006d 100644
--- a/adb/transport.cpp
+++ b/adb/transport.cpp
@@ -1040,12 +1040,6 @@ size_t atransport::get_max_payload() const {
     return max_payload;
 }
 
-namespace {
-
-constexpr char kFeatureStringDelimiter = ',';
-
-}  // namespace
-
 const FeatureSet& supported_features() {
     // Local static allocation to avoid global non-POD variables.
     static const FeatureSet* features = new FeatureSet{
@@ -1059,7 +1053,7 @@ const FeatureSet& supported_features() {
 }
 
 std::string FeatureSetToString(const FeatureSet& features) {
-    return android::base::Join(features, kFeatureStringDelimiter);
+    return android::base::Join(features, ',');
 }
 
 FeatureSet StringToFeatureSet(const std::string& features_string) {
@@ -1067,7 +1061,7 @@ FeatureSet StringToFeatureSet(const std::string& features_string) {
         return FeatureSet();
     }
 
-    auto names = android::base::Split(features_string, {kFeatureStringDelimiter});
+    auto names = android::base::Split(features_string, ",");
     return FeatureSet(names.begin(), names.end());
 }
 
diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp
index 4fd483b574..8353d89f29 100644
--- a/adb/transport_local.cpp
+++ b/adb/transport_local.cpp
@@ -187,8 +187,8 @@ static void PollAllLocalPortsForEmulator() {
 }
 
 // Retry the disconnected local port for 60 times, and sleep 1 second between two retries.
-constexpr uint32_t LOCAL_PORT_RETRY_COUNT = 60;
-constexpr auto LOCAL_PORT_RETRY_INTERVAL = 1s;
+static constexpr uint32_t LOCAL_PORT_RETRY_COUNT = 60;
+static constexpr auto LOCAL_PORT_RETRY_INTERVAL = 1s;
 
 struct RetryPort {
     int port;
-- 
GitLab