Bläddra i källkod

lang: Remove `try_to_vec` usage (#2744)

acheron 1 år sedan
förälder
incheckning
c4f14b9f6f
3 ändrade filer med 6 tillägg och 3 borttagningar
  1. 3 1
      CHANGELOG.md
  2. 3 1
      lang/syn/src/codegen/program/handlers.rs
  3. 0 1
      tests/cpi-returns/tsconfig.json

+ 3 - 1
CHANGELOG.md

@@ -29,7 +29,9 @@ The minor version will be incremented upon a breaking change and the patch versi
 - cli: Fix commit based `anchor_version` override ([#2704](https://github.com/coral-xyz/anchor/pull/2704)).
 - spl: Fix compilation with `shmem` feature enabled ([#2722](https://github.com/coral-xyz/anchor/pull/2722)).
 - cli: Localhost default test validator address changes from `localhost` to `127.0.0.1`, NodeJS 17 IP resolution changes for IPv6 ([#2725](https://github.com/coral-xyz/anchor/pull/2725)).
-- lang: Eliminate temporary Vec allocations when serialising objects with discriminant ([#2691](https://github.com/coral-xyz/anchor/pull/2691)).
+- lang: Eliminate temporary Vec allocations when serializing data with discriminant and set the default capacity to 256 bytes ([#2691](https://github.com/coral-xyz/anchor/pull/2691)).
+- lang: Allow custom lifetime in Accounts structure ([#2741](https://github.com/coral-xyz/anchor/pull/2741)).
+- lang: Remove `try_to_vec` usage while setting the return data in order to reduce heap memory usage ([#2744](https://github.com/coral-xyz/anchor/pull/2744))
 
 ### Breaking
 

+ 3 - 1
lang/syn/src/codegen/program/handlers.rs

@@ -107,7 +107,9 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
             let maybe_set_return_data = match ret_type.to_string().as_str() {
                 "()" => quote! {},
                 _ => quote! {
-                    anchor_lang::solana_program::program::set_return_data(&result.try_to_vec().unwrap());
+                    let mut return_data = Vec::with_capacity(256);
+                    result.serialize(&mut return_data).unwrap();
+                    anchor_lang::solana_program::program::set_return_data(&return_data);
                 },
             };
             quote! {

+ 0 - 1
tests/cpi-returns/tsconfig.json

@@ -1,7 +1,6 @@
 {
   "compilerOptions": {
     "types": ["mocha", "chai"],
-    "typeRoots": ["./node_modules/@types"],
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",