From 25cce38f50123d0ca88fb0920df6acdde05a53ff Mon Sep 17 00:00:00 2001
From: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
Date: Sun, 20 Sep 2015 00:46:09 -0700
Subject: Inline widen_ascii to get rid of an extra strlen call

Also since this function is only used once and is not defined in regular mode
to avoid warnings this simplifies code a bit.
---
 src/pugixml.cpp | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

(limited to 'src')

diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index da0e9e4..413e342 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -221,15 +221,6 @@ PUGI__NS_BEGIN
 		return static_cast<size_t>(end - s);
 	#endif
 	}
-
-#ifdef PUGIXML_WCHAR_MODE
-	// Convert string to wide string, assuming all symbols are ASCII
-	PUGI__FN void widen_ascii(wchar_t* dest, const char* source)
-	{
-		for (const char* i = source; *i; ++i) *dest++ = *i;
-		*dest = 0;
-	}
-#endif
 PUGI__NS_END
 
 // auto_ptr-like object for exception recovery
@@ -4563,13 +4554,15 @@ PUGI__NS_BEGIN
 
 	// set value with conversion functions
 	template <typename String, typename Header>
-	PUGI__FN bool set_value_buffer(String& dest, Header& header, uintptr_t header_mask, char (&buf)[128])
+	PUGI__FN bool set_value_ascii(String& dest, Header& header, uintptr_t header_mask, char (&buf)[128])
 	{
 	#ifdef PUGIXML_WCHAR_MODE
 		char_t wbuf[128];
-		impl::widen_ascii(wbuf, buf);
 
-		return strcpy_insitu(dest, header, header_mask, wbuf, strlength(wbuf));
+		size_t offset = 0;
+		for (; buf[offset]; ++offset) wbuf[offset] = buf[offset];
+
+		return strcpy_insitu(dest, header, header_mask, wbuf, offset);
 	#else
 		return strcpy_insitu(dest, header, header_mask, buf, strlength(buf));
 	#endif
@@ -4601,7 +4594,7 @@ PUGI__NS_BEGIN
 		char buf[128];
 		sprintf(buf, "%.9g", value);
 
-		return set_value_buffer(dest, header, header_mask, buf);
+		return set_value_ascii(dest, header, header_mask, buf);
 	}
 
 	template <typename String, typename Header>
@@ -4610,7 +4603,7 @@ PUGI__NS_BEGIN
 		char buf[128];
 		sprintf(buf, "%.17g", value);
 
-		return set_value_buffer(dest, header, header_mask, buf);
+		return set_value_ascii(dest, header, header_mask, buf);
 	}
 	
 	template <typename String, typename Header>
-- 
cgit v1.2.3