nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: go-kratos/kratos
Pull request #3660 (2025-05-13 05:21:59)

perf(config/env): use strings.LastIndexByte instead of strings.LastIndex
`strings.LastIndexByte` offers better performance than `strings.LastIndex`.


1911860538: > Maybe we should include a benchmark test for performance-related changes @1911860538
## benchmark code
```go
func BenchmarkFormat(b *testing.B) {
	for i := 0; i < b.N; i++ {
		format("abc.txt")
	}
}
```

## benchmark output before optimization
```text
goos: darwin
goarch: amd64
pkg: github.com/go-kratos/kratos/v2/config/file
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkFormat
BenchmarkFormat-8   	276620788	         4.317 ns/op
PASS

Process finished with the exit code 0
```

## benchmark output after optimization
```text
goos: darwin
goarch: amd64
pkg: github.com/go-kratos/kratos/v2/config/file
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkFormat
BenchmarkFormat-8   	338712090	         3.683 ns/op
PASS

Process finished with the exit code 0
```

kagaya85: Thanks for the update, please rebase the code☺️
1911860538: > Thanks for the update, please rebase the code☺️

Done.

Patch:
diff --git a/config/file/format.go b/config/file/format.go
index 6cce7d7b..69c44c8c 100644
--- a/config/file/format.go
+++ b/config/file/format.go
@@ -3,7 +3,7 @@ package file
 import "strings"
 
 func format(name string) string {
-	if idx := strings.LastIndex(name, "."); idx >= 0 {
+	if idx := strings.LastIndexByte(name, '.'); idx >= 0 {
 		return name[idx+1:]
 	}
 	return ""


Test patch:
diff --git a/config/file/format_test.go b/config/file/format_test.go
index 75185cc6..a7aaae0c 100644
--- a/config/file/format_test.go
+++ b/config/file/format_test.go
@@ -21,6 +21,10 @@ func TestFormat(t *testing.T) {
 			input:  ".",
 			expect: "",
 		},
+		{
+			input:  "a",
+			expect: "",
+		},
 		{
 			input:  "a.",
 			expect: "",
@@ -33,6 +37,10 @@ func TestFormat(t *testing.T) {
 			input:  "a.b",
 			expect: "b",
 		},
+		{
+			input:  "a.b.c",
+			expect: "c",
+		},
 	}
 	for _, v := range tests {
 		content := format(v.input)
@@ -41,3 +49,9 @@ func TestFormat(t *testing.T) {
 		}
 	}
 }
+
+func BenchmarkFormat(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		format("abc.txt")
+	}
+}
Repository: rstudio/vetiver-python
Pull request #205 (2024-01-03 22:31:48)

ENH: load dotenv file into generated app.py file
Automatically load `.env` files into any `app.py` file that is generated. This is particularly useful for authorizing Posit Connect boards.


Patch:
diff --git a/setup.cfg b/setup.cfg
index ef3a541..04c9f2e 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -32,10 +32,12 @@ install_requires =
     requests
     pins>=0.7.1
     rsconnect-python>=1.11.0
+    python-dotenv
     plotly
     pip-tools
     httpx
 
+
 [options.extras_require]
 all =
     vetiver[dev]
diff --git a/vetiver/write_fastapi.py b/vetiver/write_fastapi.py
index 116f14c..f378b23 100644
--- a/vetiver/write_fastapi.py
+++ b/vetiver/write_fastapi.py
@@ -104,7 +104,9 @@ def write_app(
         f = open(file, "x")
 
     app = f"""from vetiver import VetiverModel
+from dotenv import load_dotenv, find_dotenv
 {_glue_required_pkgs(infra_pkgs)}
+load_dotenv(find_dotenv())
 
 b = pins.{load_board}
 {pin_read}


Test patch:
diff --git a/vetiver/tests/test_write_app.py b/vetiver/tests/test_write_app.py
index 2c18727..cb07a17 100644
--- a/vetiver/tests/test_write_app.py
+++ b/vetiver/tests/test_write_app.py
@@ -26,9 +26,11 @@ def test_write_app(vetiver_model_creation):
         assert (
             contents
             == f"""from vetiver import VetiverModel
+from dotenv import load_dotenv, find_dotenv
 import vetiver
 import pins
 
+load_dotenv(find_dotenv())
 
 b = pins.board_folder({repr(tempdir)}, allow_pickle_read=True)
 v = VetiverModel.from_pin(b, 'model', version = {repr(version)})