summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/core/slang-io.cpp69
-rw-r--r--source/core/slang-io.h5
-rw-r--r--source/core/slang-platform.cpp2
-rw-r--r--source/core/slang-smart-pointer.h6
-rw-r--r--source/core/slang-string.h4
5 files changed, 47 insertions, 39 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 01c8b38e0..3e0aa22a3 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -134,53 +134,52 @@ namespace Slang
else
return "";
}
- String Path::combine(const String& path1, const String& path2)
- {
- if (path1.getLength() == 0) return path2;
-
- StringBuilder sb;
- combineBuilder(path1.getUnownedSlice(), path2.getUnownedSlice(), sb);
- return sb.ProduceString();
- }
- /* static */void Path::combineBuilder(const UnownedStringSlice& path1, const UnownedStringSlice& path2, StringBuilder& outBuilder)
+
+ /* static */void Path::append(StringBuilder& ioBuilder, const UnownedStringSlice& path)
{
- outBuilder.Clear();
- // Make sure we have the space for the full result
- outBuilder.EnsureCapacity(path1.size() + 2 + path2.size());
-
- if (path1.size() == 0)
+ if (ioBuilder.getLength() == 0)
{
- outBuilder.append(path2);
+ ioBuilder.append(path);
return;
}
-
- outBuilder.append(path1);
-
- // If path1 doesn't end in a delimiter, add one
- if (!isDelimiter(path1[path1.size() - 1]))
+ if (path.size() > 0)
{
- outBuilder.append(kPathDelimiter);
+ // If ioBuilder doesn't end in a delimiter, add one
+ if (!isDelimiter(ioBuilder[ioBuilder.getLength() - 1]))
+ {
+ ioBuilder.append(kPathDelimiter);
+ }
+ // Check that path doesn't start with a path delimiter
+ SLANG_ASSERT(!isDelimiter(path[0]));
+ // Append the path
+ ioBuilder.append(path);
}
+ }
+
+ /* static */void Path::combineIntoBuilder(const UnownedStringSlice& path1, const UnownedStringSlice& path2, StringBuilder& outBuilder)
+ {
+ outBuilder.Clear();
+ outBuilder.Append(path1);
+ append(outBuilder, path2);
+ }
- // Check that path2 doesn't start with a path delimiter
- if (path2.size() > 0)
+ String Path::combine(const String& path1, const String& path2)
+ {
+ if (path1.getLength() == 0)
{
- SLANG_ASSERT(!isDelimiter(path2[0]));
+ return path2;
}
- // Append the second path
- outBuilder.append(path2);
- }
+ StringBuilder sb;
+ combineIntoBuilder(path1.getUnownedSlice(), path2.getUnownedSlice(), sb);
+ return sb.ProduceString();
+ }
String Path::combine(const String& path1, const String& path2, const String& path3)
{
- StringBuilder sb(path1.getLength()+path2.getLength()+path3.getLength()+3);
- sb.Append(path1);
- if (!path1.endsWith('\\') && !path1.endsWith('/'))
- sb.Append(kPathDelimiter);
- sb.Append(path2);
- if (!path2.endsWith('\\') && !path2.endsWith('/'))
- sb.Append(kPathDelimiter);
- sb.Append(path3);
+ StringBuilder sb;
+ sb.append(path1);
+ append(sb, path2.getUnownedSlice());
+ append(sb, path3.getUnownedSlice());
return sb.ProduceString();
}
diff --git a/source/core/slang-io.h b/source/core/slang-io.h
index 91cfaf290..da63e9c20 100644
--- a/source/core/slang-io.h
+++ b/source/core/slang-io.h
@@ -34,7 +34,10 @@ namespace Slang
static String combine(const String& path1, const String& path2, const String& path3);
/// Combine path sections and store the result in outBuilder
- static void combineBuilder(const UnownedStringSlice& path1, const UnownedStringSlice& path2, StringBuilder& outBuilder);
+ static void combineIntoBuilder(const UnownedStringSlice& path1, const UnownedStringSlice& path2, StringBuilder& outBuilder);
+
+ /// Append a path, taking into account path separators onto the end of ioBuilder
+ static void append(StringBuilder& ioBuilder, const UnownedStringSlice& path);
static bool createDirectory(const String& path);
diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp
index 8055d3e55..4f4c805ac 100644
--- a/source/core/slang-platform.cpp
+++ b/source/core/slang-platform.cpp
@@ -38,7 +38,7 @@ namespace Slang
StringBuilder platformFileNameBuilder;
SharedLibrary::appendPlatformFileName(filename.getUnownedSlice(), platformFileNameBuilder);
- Path::combineBuilder(parent.getUnownedSlice(), platformFileNameBuilder.getUnownedSlice(), outPath);
+ Path::combineIntoBuilder(parent.getUnownedSlice(), platformFileNameBuilder.getUnownedSlice(), outPath);
}
else
{
diff --git a/source/core/slang-smart-pointer.h b/source/core/slang-smart-pointer.h
index bae30de37..ebc6f20b0 100644
--- a/source/core/slang-smart-pointer.h
+++ b/source/core/slang-smart-pointer.h
@@ -235,6 +235,12 @@ namespace Slang
return rs;
}
+ SLANG_FORCE_INLINE void setNull()
+ {
+ releaseReference(pointer);
+ pointer = nullptr;
+ }
+
/// Get ready for writing (nulls contents)
SLANG_FORCE_INLINE T** writeRef() { *this = nullptr; return &pointer; }
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 8a9e83cd1..560d137db 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -511,7 +511,7 @@ namespace Slang
~String()
{
- m_buffer = 0;
+ m_buffer.setNull();
}
String & operator=(const String & str)
@@ -980,7 +980,7 @@ namespace Slang
void Clear()
{
- m_buffer = 0;
+ m_buffer.setNull();
}
};