Use ImmutableString in ImageFunctionHLSL
This code is analoguous to the code in TextureFunctionHLSL and is now
implemented in a similar manner.
BUG=angleproject:2267
TEST=angle_unittests, angle_end2end_tests
Change-Id: Ie3503766217dad4f3848f2d4b2fc3f62b3edce0c
Reviewed-on: https://chromium-review.googlesource.com/1110366
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/ImageFunctionHLSL.cpp b/src/compiler/translator/ImageFunctionHLSL.cpp
index 64e4c0a..20f8334 100644
--- a/src/compiler/translator/ImageFunctionHLSL.cpp
+++ b/src/compiler/translator/ImageFunctionHLSL.cpp
@@ -169,28 +169,34 @@
UNREACHABLE();
}
-TString ImageFunctionHLSL::ImageFunction::name() const
+ImmutableString ImageFunctionHLSL::ImageFunction::name() const
{
- TString name = "gl_image";
+ static const ImmutableString kGlImageName("gl_image");
+
+ ImmutableString suffix(nullptr);
if (readonly)
{
- name += TextureTypeSuffix(image, imageInternalFormat);
+ suffix = ImmutableString(TextureTypeSuffix(image, imageInternalFormat));
}
else
{
- name += RWTextureTypeSuffix(image, imageInternalFormat);
+ suffix = ImmutableString(RWTextureTypeSuffix(image, imageInternalFormat));
}
+ ImmutableStringBuilder name(kGlImageName.length() + suffix.length() + 5u);
+
+ name << kGlImageName << suffix;
+
switch (method)
{
case Method::SIZE:
- name += "Size";
+ name << "Size";
break;
case Method::LOAD:
- name += "Load";
+ name << "Load";
break;
case Method::STORE:
- name += "Store";
+ name << "Store";
break;
default:
UNREACHABLE();
@@ -293,10 +299,10 @@
std::tie(rhs.image, rhs.type, rhs.method, rhs.readonly);
}
-TString ImageFunctionHLSL::useImageFunction(const ImmutableString &name,
- const TBasicType &type,
- TLayoutImageInternalFormat imageInternalFormat,
- bool readonly)
+ImmutableString ImageFunctionHLSL::useImageFunction(const ImmutableString &name,
+ const TBasicType &type,
+ TLayoutImageInternalFormat imageInternalFormat,
+ bool readonly)
{
ASSERT(IsImage(type));
ImageFunction imageFunction;
diff --git a/src/compiler/translator/ImageFunctionHLSL.h b/src/compiler/translator/ImageFunctionHLSL.h
index c58213a..7926512 100644
--- a/src/compiler/translator/ImageFunctionHLSL.h
+++ b/src/compiler/translator/ImageFunctionHLSL.h
@@ -25,10 +25,10 @@
public:
// Returns the name of the image function implementation to caller.
// The name that's passed in is the name of the GLSL image function that it should implement.
- TString useImageFunction(const ImmutableString &name,
- const TBasicType &type,
- TLayoutImageInternalFormat imageInternalFormat,
- bool readonly);
+ ImmutableString useImageFunction(const ImmutableString &name,
+ const TBasicType &type,
+ TLayoutImageInternalFormat imageInternalFormat,
+ bool readonly);
void imageFunctionHeader(TInfoSinkBase &out);
@@ -53,7 +53,7 @@
SNORM_FLOAT4
};
- TString name() const;
+ ImmutableString name() const;
bool operator<(const ImageFunction &rhs) const;
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index 121dd11..3245887 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -1941,8 +1941,8 @@
else if (node->getFunction()->isImageFunction())
{
const ImmutableString &name = node->getFunction()->name();
- TType type = (*arguments)[0]->getAsTyped()->getType();
- TString imageFunctionName = mImageFunctionHLSL->useImageFunction(
+ TType type = (*arguments)[0]->getAsTyped()->getType();
+ const ImmutableString &imageFunctionName = mImageFunctionHLSL->useImageFunction(
name, type.getBasicType(), type.getLayoutQualifier().imageInternalFormat,
type.getMemoryQualifier().readonly);
out << imageFunctionName << "(";