Skip to content

Commit

Permalink
Use text_substr for getting top comment
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhangulbiz committed Mar 20, 2023
1 parent 5929fda commit 9531cfd
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions src/backend/distributed/utils/attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ static int CreateTenantStats(MultiTenantMonitor *monitor);
static int FindTenantStats(MultiTenantMonitor *monitor);
static size_t MultiTenantMonitorshmemSize(void);
static char * ExtractTopComment(const char *inputString);
static char * Substring(const char *str, int start, int end);
static char * EscapeCommentChars(const char *str);
static char * UnescapeCommentChars(const char *str);

Expand Down Expand Up @@ -639,40 +638,17 @@ ExtractTopComment(const char *inputString)

if (commentEndCharsIndex > commentStartCharsLength)
{
return Substring(inputString, commentStartCharsLength, commentEndCharsIndex);
Datum substringTextDatum = DirectFunctionCall3(text_substr, PointerGetDatum(inputString),
Int32GetDatum(commentStartCharsLength),
Int32GetDatum(commentEndCharsIndex - commentStartCharsLength));
return TextDatumGetCString(substringTextDatum);
}
else
{
return NULL;
}
}


/* Extracts a substring from the input string between the specified start and end indices.*/
static char *
Substring(const char *str, int start, int end)
{
int len = strlen(str);

/* Ensure start and end are within the bounds of the string */
if (start < 0 || end > len || start > end)
{
return NULL;
}

/* Allocate memory for the substring */
char *substr = (char *) palloc((end - start + 1) * sizeof(char));

/* Copy the substring to the new memory location */
strncpy_s(substr, end - start + 1, str + start, end - start);

/* Add null terminator to end the substring */
substr[end - start] = '\0';

return substr;
}


/* EscapeCommentChars adds a backslash before each occurrence of '*' or '/' in the input string */
static char *
EscapeCommentChars(const char *str)
Expand Down

0 comments on commit 9531cfd

Please sign in to comment.